(function () {
    "use strict"; function DI(n, t) { for (var e = 0; e < t.length; e++) { const s = t[e]; if (typeof s != "string" && !Array.isArray(s)) { for (const o in s) if (o !== "default" && !(o in n)) { const r = Object.getOwnPropertyDescriptor(s, o); r && Object.defineProperty(n, o, r.get ? r : { enumerable: !0, get: () => s[o] }) } } } return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" })) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const WI = 1e-7, MI = 1e-4; class ef { constructor(t, e) { this.backend = t, this.dataMover = e, this.data = new WeakMap, this.dataIdsCount = 0 } get(t) { return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t) } set(t, e) { this.dataIdsCount++, this.data.set(t, e) } has(t) { return this.data.has(t) } delete(t) { return this.dataIdsCount--, this.data.delete(t) } numDataIds() { return this.dataIdsCount } } class Al { refCount(t) { return Oe("refCount") } incRef(t) { return Oe("incRef") } timerAvailable() { return !0 } time(t) { return Oe("time") } read(t) { return Oe("read") } readSync(t) { return Oe("readSync") } readToGPU(t, e) { return Oe("readToGPU") } numDataIds() { return Oe("numDataIds") } disposeData(t, e) { return Oe("disposeData") } write(t, e, s) { return Oe("write") } move(t, e, s, o, r) { return Oe("move") } createTensorFromGPUData(t, e, s) { return Oe("createTensorFromGPUData") } memory() { return Oe("memory") } floatPrecision() { return Oe("floatPrecision") } epsilon() { return this.floatPrecision() === 32 ? WI : MI } dispose() { return Oe("dispose") } } function Oe(n) { throw new Error(`'${n}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function FI(n) { let t = n.length, e = 0; for (; t > 0;)e = Math.random() * t | 0, t--, No(n, t, e) } function Xs(n, t, e) { return Math.max(n, Math.min(t, e)) } function Ol(n) { return n % 2 === 0 ? n : n + 1 } function No(n, t, e) { const s = n[t]; n[t] = n[e], n[e] = s } function VI(n) { let t = 0; for (let e = 0; e < n.length; e++)t += n[e]; return t } function v(n, t) { if (!n) throw new Error(typeof t == "string" ? t : t()) } function Pl(n, t, e = "") { v(Rt(n, t), () => e + ` Shapes ${n} and ${t} must match`) } function Kl(n) { v(n != null, () => "The input to the tensor constructor must be a non-null value.") } function Z(n) { if (n.length === 0) return 1; let t = n[0]; for (let e = 1; e < n.length; e++)t *= n[e]; return t } function Rt(n, t) { if (n === t) return !0; if (n == null || t == null || n.length !== t.length) return !1; for (let e = 0; e < n.length; e++)if (n[e] !== t[e]) return !1; return !0 } function Ro(n) { return n % 1 === 0 } function Zl(n) { const t = Math.ceil(Math.sqrt(n)); return [t, Math.ceil(n / t)] } function $o(n, t) { return t <= n.length ? n : n + " ".repeat(t - n.length) } function nf(n, t = o => 0, e, s) { return new Promise((o, r) => { let i = 0; const a = () => { if (n()) { o(); return } i++; const c = t(i); if (e != null && i >= e) { r(); return } s != null ? s(a, c) : setTimeout(a, c) }; a() }) } function sf(n, t) { let e = 1, s = -1; for (let r = 0; r < n.length; ++r)if (n[r] >= 0) e *= n[r]; else if (n[r] === -1) { if (s !== -1) throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${r}`); s = r } else if (n[r] < 0) throw Error(`Shapes can not be < 0. Found ${n[r]} at dim ${r}`); if (s === -1) { if (t > 0 && t !== e) throw Error(`Size(${t}) must match the product of shape ${n}`); return n } if (e === 0) throw Error(`Cannot infer the missing size in [${n}] when there are 0 elements`); if (t % e !== 0) throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${e}`); const o = n.slice(); return o[s] = t / e, o } function It(n, t) { const e = t.length; return n = n == null ? t.map((s, o) => o) : [].concat(n), v(n.every(s => s >= -e && s < e), () => `All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`), v(n.every(s => Ro(s)), () => `All values in axis param must be integers but got axis ${n}`), n.map(s => s < 0 ? e + s : s) } function ds(n, t) { const e = [], s = [], o = t != null && Array.isArray(t) && t.length === 0, r = t == null || o ? null : It(t, n).sort(); let i = 0; for (let a = 0; a < n.length; ++a) { if (r != null) { if (r[i] === a && n[a] !== 1) throw new Error(`Can't squeeze axis ${a} since its dim '${n[a]}' is not 1`); (r[i] == null || r[i] > a) && n[a] === 1 && (e.push(n[a]), s.push(a)), r[i] <= a && i++ } n[a] !== 1 && (e.push(n[a]), s.push(a)) } return { newShape: e, keptDims: s } } function xe(n, t) { let e = null; if (n == null || n === "float32") e = new Float32Array(t); else if (n === "int32") e = new Int32Array(t); else if (n === "bool") e = new Uint8Array(t); else throw new Error(`Unknown data type ${n}`); return e } function ne(n, t) { let e = null; if (n == null || n === "float32") e = new Float32Array(t); else if (n === "int32") e = new Int32Array(t); else if (n === "bool") e = new Uint8Array(t); else if (n === "string") e = new Array(t); else throw new Error(`Unknown data type ${n}`); return e } function zI(n, t) { for (let e = 0; e < n.length; e++) { const s = n[e]; if (isNaN(s) || !isFinite(s)) throw Error(`A tensor of type ${t} being uploaded contains ${s}.`) } } function XI(n) { return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string" } function of(n, t) { return !(t === "complex64" || t === "float32" && n !== "complex64" || t === "int32" && n !== "float32" && n !== "complex64" || t === "bool" && n === "bool") } function fa(n) { if (n === "float32" || n === "int32") return 4; if (n === "complex64") return 8; if (n === "bool") return 1; throw new Error(`Unknown dtype ${n}`) } function AI(n) { if (n == null) return 0; let t = 0; return n.forEach(e => t += e.length), t } function br(n) { return typeof n == "string" || n instanceof String } function OI(n) { return typeof n == "boolean" } function Bl(n) { return typeof n == "number" } function xr(n) { return Array.isArray(n) ? xr(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray ? "int32" : Bl(n) ? "float32" : br(n) ? "string" : OI(n) ? "bool" : "float32" } function Hl(n) { return !!(n && n.constructor && n.call && n.apply) } function _l(n, t) { for (let e = t; e < n; ++e)if (n % e === 0) return e; return n } function ct(n) { const t = n.length; if (t < 2) return []; const e = new Array(t - 1); e[t - 2] = n[t - 1]; for (let s = t - 3; s >= 0; --s)e[s] = e[s + 1] * n[s + 1]; return e } function rf(n, t, e, s = !1) { const o = new Array; if (t.length === 1) { const r = t[0] * (s ? 2 : 1); for (let i = 0; i < r; i++)o[i] = e[n + i] } else { const r = t[0], i = t.slice(1), a = i.reduce((c, l) => c * l) * (s ? 2 : 1); for (let c = 0; c < r; c++)o[c] = rf(n + c * a, i, e, s) } return o } function wn(n, t, e = !1) { if (n.length === 0) return t[0]; const s = n.reduce((o, r) => o * r) * (e ? 2 : 1); if (s === 0) return []; if (s !== t.length) throw new Error(`[${n}] does not match the input size ${t.length}${e ? " for a complex tensor" : ""}.`); return rf(0, n, t, e) } function PI(n, t) { if (Array.isArray(n)) return n; if (t === "float32") return n instanceof Float32Array ? n : new Float32Array(n); if (t === "int32") return n instanceof Int32Array ? n : new Int32Array(n); if (t === "bool" || t === "string") return Uint8Array.from(new Int32Array(n)); throw new Error(`Unknown dtype ${t}`) } function Ul(n, t) { const e = Se(n, t); for (let s = 0; s < e.length; s++)e[s] = 1; return e } function Se(n, t) { if (t == null || t === "float32" || t === "complex64") return new Float32Array(n); if (t === "int32") return new Int32Array(n); if (t === "bool") return new Uint8Array(n); throw new Error(`Unknown data type ${t}`) } function af(n, t) { const e = n.reduce((s, o) => s * o, 1); if (t == null || t === "float32") return wn(n, new Float32Array(e)); if (t === "int32") return wn(n, new Int32Array(e)); if (t === "bool") return wn(n, new Uint8Array(e)); throw new Error(`Unknown data type ${t}`) } function jn(n) { n.forEach(t => { v(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${n}].`) }) } function Vn(n, t, e) { if (t === 0) return 0; if (t === 1) return n[0]; let s = n[n.length - 1]; for (let o = 0; o < n.length - 1; ++o)s += e[o] * n[o]; return s } function Go(n, t, e) { if (t === 0) return []; if (t === 1) return [n]; const s = new Array(t); for (let o = 0; o < s.length - 1; ++o)s[o] = Math.floor(n / e[o]), n -= s[o] * e[o]; return s[s.length - 1] = n, s } function Yl(n) { return n && n.then && typeof n.then == "function" }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const cf = "tfjsflags"; class KI { constructor(t) { this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = ZI, this.populateURLFlags() } setPlatform(t, e) { this.platform != null && (A().getBool("IS_TEST") || A().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = e } registerFlag(t, e, s) { if (this.flagRegistry[t] = { evaluationFn: e, setHook: s }, this.urlFlags[t] != null) { const o = this.urlFlags[t]; A().getBool("IS_TEST") || A().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${o}.`), this.set(t, o) } } async getAsync(t) { return t in this.flags ? this.flags[t] : (this.flags[t] = await this.evaluateFlag(t), this.flags[t]) } get(t) { if (t in this.flags) return this.flags[t]; const e = this.evaluateFlag(t); if (Yl(e)) throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`); return this.flags[t] = e, this.flags[t] } getNumber(t) { return this.get(t) } getBool(t) { return this.get(t) } getFlags() { return this.flags } get features() { return this.flags } set(t, e) { if (this.flagRegistry[t] == null) throw new Error(`Cannot set flag ${t} as it has not been registered.`); this.flags[t] = e, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(e) } evaluateFlag(t) { if (this.flagRegistry[t] == null) throw new Error(`Cannot evaluate flag '${t}': no evaluation function found.`); return this.flagRegistry[t].evaluationFn() } setFlags(t) { this.flags = Object.assign({}, t) } reset() { this.flags = {}, this.urlFlags = {}, this.populateURLFlags() } populateURLFlags() { if (typeof this.global > "u" || typeof this.global.location > "u" || typeof this.global.location.search > "u") return; const t = this.getQueryParams(this.global.location.search); cf in t && t[cf].split(",").forEach(s => { const [o, r] = s.split(":"); this.urlFlags[o] = HI(o, r) }) } } function ZI(n) { const t = {}; return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...s) => (BI(t, s[0], s[1]), s.join("="))), t } function BI(n, t, e) { n[decodeURIComponent(t)] = decodeURIComponent(e || "") } function HI(n, t) { if (t = t.toLowerCase(), t === "true" || t === "false") return t === "true"; if (`${+t}` === t) return +t; throw new Error(`Could not parse value flag value ${t} for flag ${n}.`) } function A() { return lf } let lf = null; function _I(n) { lf = n }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */let Ql; function uf() { if (Ql == null) { let n; if (typeof window < "u") n = window; else if (typeof global < "u") n = global; else if (typeof process < "u") n = process; else if (typeof self < "u") n = self; else throw new Error("Could not find a global object"); Ql = n } return Ql } function UI() { const n = uf(); return n._tfGlobals == null && (n._tfGlobals = new Map), n._tfGlobals } function Jl(n, t) { const e = UI(); if (e.has(n)) return e.get(n); { const s = t(); return e.set(n, s), e.get(n) } } const ma = "Abs", yr = "Acos", Ir = "Acosh", Lo = "Add", jl = "AddN", ql = "All", tu = "Any", ga = "ArgMax", ba = "ArgMin", Cr = "Asin", wr = "Asinh", vr = "Atan", Sr = "Atanh", kr = "Atan2", xa = "AvgPool", eu = "AvgPoolGrad", ya = "AvgPool3D", nu = "AvgPool3DGrad", Ia = "BatchMatMul", Ca = "BatchToSpaceND", su = "Bincount", YI = "BroadcastTo", df = "BroadcastArgs", Tr = "Cast", Nr = "Ceil", Rr = "ClipByValue", ou = "Complex", wa = "ComplexAbs", va = "Concat", Sa = "Conv2D", ru = "Conv2DBackpropFilter", ka = "Conv2DBackpropInput", Ta = "Conv3D", iu = "Conv3DBackpropFilterV2", au = "Conv3DBackpropInputV2", $r = "Cos", Gr = "Cosh", cu = "Cumprod", Na = "Cumsum", lu = "CropAndResize", uu = "DenseBincount", du = "DepthToSpace", Ra = "DepthwiseConv2dNative", hu = "DepthwiseConv2dNativeBackpropFilter", pu = "DepthwiseConv2dNativeBackpropInput", hf = "Diag", $a = "Dilation2D", fu = "Dilation2DBackpropInput", mu = "Dilation2DBackpropFilter", Lr = "RealDiv", pf = "Einsum", Er = "Elu", gu = "EluGrad", Dr = "Erf", Ga = "Equal", Wr = "Exp", La = "ExpandDims", Mr = "Expm1", bu = "FFT", xu = "Fill", yu = "FlipLeftRight", Fr = "Floor", Vr = "FloorDiv", Ea = "FusedBatchNorm", Da = "GatherV2", ff = "GatherNd", Wa = "Greater", zr = "GreaterEqual", Xr = "Identity", Iu = "IFFT", Cu = "Imag", Ar = "IsFinite", Or = "IsInf", Pr = "IsNan", Ma = "LeakyRelu", Fa = "Less", Va = "LessEqual", mf = "LinSpace", Kr = "Log", Zr = "Log1p", za = "LogicalAnd", Xa = "LogicalNot", Aa = "LogicalOr", QI = "LogSoftmax", Oa = "LRN", wu = "LRNGrad", Pa = "Max", Br = "Maximum", Ka = "MaxPool", vu = "MaxPoolGrad", Za = "MaxPool3D", Su = "MaxPool3DGrad", gf = "MaxPoolWithArgmax", Ba = "Mean", Ha = "Min", Hr = "Minimum", _a = "MirrorPad", _r = "Mod", bf = "Multinomial", Ur = "Multiply", Ua = "Neg", Ya = "NotEqual", ku = "NonMaxSuppressionV3", Tu = "NonMaxSuppressionV4", Nu = "NonMaxSuppressionV5", Qa = "OnesLike", Ja = "OneHot", ja = "Pack", qa = "PadV2", Yr = "Pow", tc = "Prelu", ec = "Prod", xf = "RaggedGather", yf = "RaggedRange", If = "RaggedTensorToTensor", Ru = "Range", $u = "Real", Qr = "Reciprocal", Jr = "Relu", nc = "Reshape", sc = "ResizeNearestNeighbor", Gu = "ResizeNearestNeighborGrad", oc = "ResizeBilinear", Lu = "ResizeBilinearGrad", jr = "Relu6", rc = "Reverse", qr = "Round", ti = "Rsqrt", Cf = "ScatterNd", wf = "SearchSorted", ic = "Select", ei = "Selu", ac = "Slice", ni = "Sin", si = "Sinh", oi = "Sign", ri = "Sigmoid", ii = "Softplus", ai = "Sqrt", cc = "Sum", lc = "SpaceToBatchND", uc = "SplitV", dc = "Softmax", vf = "SparseFillEmptyRows", Sf = "SparseReshape", kf = "SparseSegmentMean", Tf = "SparseSegmentSum", Nf = "SparseToDense", ci = "SquaredDifference", Eu = "Square", Du = "StridedSlice", Rf = "StringNGrams", $f = "StringSplit", Gf = "StringToHashBucketFast", li = "Sub", ui = "Tan", di = "Tanh", hi = "Tile", Wu = "TopK", Mu = "Transform", Eo = "Transpose", Fu = "Unique", hc = "Unpack", pc = "UnsortedSegmentSum", fc = "ZerosLike", pi = "Step", Vu = "FromPixels", zu = "RotateWithOffset", mc = "_FusedMatMul", gc = "FusedConv2D", Lf = "FusedDepthwiseConv2D";/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Qe(...n) { A().getBool("IS_TEST") || A().getBool("PROD") || console.warn(...n) } function JI(...n) { A().getBool("IS_TEST") || A().getBool("PROD") || console.log(...n) }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const bc = Jl("kernelRegistry", () => new Map), Xu = Jl("gradRegistry", () => new Map); function Au(n, t) { const e = Wf(n, t); return bc.get(e) } function Ef(n) { return Xu.get(n) } function Df(n) { const t = bc.entries(), e = []; for (; ;) { const { done: s, value: o } = t.next(); if (s) break; const [r, i] = o, [a] = r.split("_"); a === n && e.push(i) } return e } function Je(n) { const { kernelName: t, backendName: e } = n, s = Wf(t, e); bc.has(s) && Qe(`The kernel '${t}' for backend '${e}' is already registered`), bc.set(s, n) } function jI(n) { const { kernelName: t } = n; Xu.has(t) && A().getBool("DEBUG") && Qe(`Overriding the gradient for '${t}'`), Xu.set(t, n) } function Wf(n, t) { return `${t}_${n}` } var As = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function qI(n) { return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n } function tC(n) { if (n.__esModule) return n; var t = n.default; if (typeof t == "function") { var e = function s() { if (this instanceof s) { var o = [null]; o.push.apply(o, arguments); var r = Function.bind.apply(t, o); return new r } return t.apply(this, arguments) }; e.prototype = t.prototype } else e = {}; return Object.defineProperty(e, "__esModule", { value: !0 }), Object.keys(n).forEach(function (s) { var o = Object.getOwnPropertyDescriptor(n, s); Object.defineProperty(e, s, o.get ? o : { enumerable: !0, get: function () { return n[s] } }) }), e } var Mf = Pt, ln = null; try { ln = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports } catch { } function Pt(n, t, e) { this.low = n | 0, this.high = t | 0, this.unsigned = !!e } Pt.prototype.__isLong__, Object.defineProperty(Pt.prototype, "__isLong__", { value: !0 }); function Pe(n) { return (n && n.__isLong__) === !0 } Pt.isLong = Pe; var Ff = {}, Vf = {}; function Os(n, t) { var e, s, o; return t ? (n >>>= 0, (o = 0 <= n && n < 256) && (s = Vf[n], s) ? s : (e = Kt(n, (n | 0) < 0 ? -1 : 0, !0), o && (Vf[n] = e), e)) : (n |= 0, (o = -128 <= n && n < 128) && (s = Ff[n], s) ? s : (e = Kt(n, n < 0 ? -1 : 0, !1), o && (Ff[n] = e), e)) } Pt.fromInt = Os; function un(n, t) { if (isNaN(n)) return t ? Ps : dn; if (t) { if (n < 0) return Ps; if (n >= Xf) return Zf } else { if (n <= -Af) return Ke; if (n + 1 >= Af) return Kf } return n < 0 ? un(-n, t).neg() : Kt(n % Do | 0, n / Do | 0, t) } Pt.fromNumber = un; function Kt(n, t, e) { return new Pt(n, t, e) } Pt.fromBits = Kt; var xc = Math.pow; function Ou(n, t, e) { if (n.length === 0) throw Error("empty string"); if (n === "NaN" || n === "Infinity" || n === "+Infinity" || n === "-Infinity") return dn; if (typeof t == "number" ? (e = t, t = !1) : t = !!t, e = e || 10, e < 2 || 36 < e) throw RangeError("radix"); var s; if ((s = n.indexOf("-")) > 0) throw Error("interior hyphen"); if (s === 0) return Ou(n.substring(1), t, e).neg(); for (var o = un(xc(e, 8)), r = dn, i = 0; i < n.length; i += 8) { var a = Math.min(8, n.length - i), c = parseInt(n.substring(i, i + a), e); if (a < 8) { var l = un(xc(e, a)); r = r.mul(l).add(un(c)) } else r = r.mul(o), r = r.add(un(c)) } return r.unsigned = t, r } Pt.fromString = Ou; function vn(n, t) { return typeof n == "number" ? un(n, t) : typeof n == "string" ? Ou(n, t) : Kt(n.low, n.high, typeof t == "boolean" ? t : n.unsigned) } Pt.fromValue = vn; var zf = 65536, eC = 1 << 24, Do = zf * zf, Xf = Do * Do, Af = Xf / 2, Of = Os(eC), dn = Os(0); Pt.ZERO = dn; var Ps = Os(0, !0); Pt.UZERO = Ps; var Wo = Os(1); Pt.ONE = Wo; var Pf = Os(1, !0); Pt.UONE = Pf; var Pu = Os(-1); Pt.NEG_ONE = Pu; var Kf = Kt(-1, 2147483647, !1); Pt.MAX_VALUE = Kf; var Zf = Kt(-1, -1, !0); Pt.MAX_UNSIGNED_VALUE = Zf; var Ke = Kt(0, -2147483648, !1); Pt.MIN_VALUE = Ke; var tt = Pt.prototype; tt.toInt = function () { return this.unsigned ? this.low >>> 0 : this.low }, tt.toNumber = function () { return this.unsigned ? (this.high >>> 0) * Do + (this.low >>> 0) : this.high * Do + (this.low >>> 0) }, tt.toString = function (t) { if (t = t || 10, t < 2 || 36 < t) throw RangeError("radix"); if (this.isZero()) return "0"; if (this.isNegative()) if (this.eq(Ke)) { var e = un(t), s = this.div(e), o = s.mul(e).sub(this); return s.toString(t) + o.toInt().toString(t) } else return "-" + this.neg().toString(t); for (var r = un(xc(t, 6), this.unsigned), i = this, a = ""; ;) { var c = i.div(r), l = i.sub(c.mul(r)).toInt() >>> 0, u = l.toString(t); if (i = c, i.isZero()) return u + a; for (; u.length < 6;)u = "0" + u; a = "" + u + a } }, tt.getHighBits = function () { return this.high }, tt.getHighBitsUnsigned = function () { return this.high >>> 0 }, tt.getLowBits = function () { return this.low }, tt.getLowBitsUnsigned = function () { return this.low >>> 0 }, tt.getNumBitsAbs = function () { if (this.isNegative()) return this.eq(Ke) ? 64 : this.neg().getNumBitsAbs(); for (var t = this.high != 0 ? this.high : this.low, e = 31; e > 0 && !(t & 1 << e); e--); return this.high != 0 ? e + 33 : e + 1 }, tt.isZero = function () { return this.high === 0 && this.low === 0 }, tt.eqz = tt.isZero, tt.isNegative = function () { return !this.unsigned && this.high < 0 }, tt.isPositive = function () { return this.unsigned || this.high >= 0 }, tt.isOdd = function () { return (this.low & 1) === 1 }, tt.isEven = function () { return (this.low & 1) === 0 }, tt.equals = function (t) { return Pe(t) || (t = vn(t)), this.unsigned !== t.unsigned && this.high >>> 31 === 1 && t.high >>> 31 === 1 ? !1 : this.high === t.high && this.low === t.low }, tt.eq = tt.equals, tt.notEquals = function (t) { return !this.eq(t) }, tt.neq = tt.notEquals, tt.ne = tt.notEquals, tt.lessThan = function (t) { return this.comp(t) < 0 }, tt.lt = tt.lessThan, tt.lessThanOrEqual = function (t) { return this.comp(t) <= 0 }, tt.lte = tt.lessThanOrEqual, tt.le = tt.lessThanOrEqual, tt.greaterThan = function (t) { return this.comp(t) > 0 }, tt.gt = tt.greaterThan, tt.greaterThanOrEqual = function (t) { return this.comp(t) >= 0 }, tt.gte = tt.greaterThanOrEqual, tt.ge = tt.greaterThanOrEqual, tt.compare = function (t) { if (Pe(t) || (t = vn(t)), this.eq(t)) return 0; var e = this.isNegative(), s = t.isNegative(); return e && !s ? -1 : !e && s ? 1 : this.unsigned ? t.high >>> 0 > this.high >>> 0 || t.high === this.high && t.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(t).isNegative() ? -1 : 1 }, tt.comp = tt.compare, tt.negate = function () { return !this.unsigned && this.eq(Ke) ? Ke : this.not().add(Wo) }, tt.neg = tt.negate, tt.add = function (t) { Pe(t) || (t = vn(t)); var e = this.high >>> 16, s = this.high & 65535, o = this.low >>> 16, r = this.low & 65535, i = t.high >>> 16, a = t.high & 65535, c = t.low >>> 16, l = t.low & 65535, u = 0, d = 0, h = 0, p = 0; return p += r + l, h += p >>> 16, p &= 65535, h += o + c, d += h >>> 16, h &= 65535, d += s + a, u += d >>> 16, d &= 65535, u += e + i, u &= 65535, Kt(h << 16 | p, u << 16 | d, this.unsigned) }, tt.subtract = function (t) { return Pe(t) || (t = vn(t)), this.add(t.neg()) }, tt.sub = tt.subtract, tt.multiply = function (t) { if (this.isZero()) return dn; if (Pe(t) || (t = vn(t)), ln) { var e = ln.mul(this.low, this.high, t.low, t.high); return Kt(e, ln.get_high(), this.unsigned) } if (t.isZero()) return dn; if (this.eq(Ke)) return t.isOdd() ? Ke : dn; if (t.eq(Ke)) return this.isOdd() ? Ke : dn; if (this.isNegative()) return t.isNegative() ? this.neg().mul(t.neg()) : this.neg().mul(t).neg(); if (t.isNegative()) return this.mul(t.neg()).neg(); if (this.lt(Of) && t.lt(Of)) return un(this.toNumber() * t.toNumber(), this.unsigned); var s = this.high >>> 16, o = this.high & 65535, r = this.low >>> 16, i = this.low & 65535, a = t.high >>> 16, c = t.high & 65535, l = t.low >>> 16, u = t.low & 65535, d = 0, h = 0, p = 0, f = 0; return f += i * u, p += f >>> 16, f &= 65535, p += r * u, h += p >>> 16, p &= 65535, p += i * l, h += p >>> 16, p &= 65535, h += o * u, d += h >>> 16, h &= 65535, h += r * l, d += h >>> 16, h &= 65535, h += i * c, d += h >>> 16, h &= 65535, d += s * u + o * l + r * c + i * a, d &= 65535, Kt(p << 16 | f, d << 16 | h, this.unsigned) }, tt.mul = tt.multiply, tt.divide = function (t) { if (Pe(t) || (t = vn(t)), t.isZero()) throw Error("division by zero"); if (ln) { if (!this.unsigned && this.high === -2147483648 && t.low === -1 && t.high === -1) return this; var e = (this.unsigned ? ln.div_u : ln.div_s)(this.low, this.high, t.low, t.high); return Kt(e, ln.get_high(), this.unsigned) } if (this.isZero()) return this.unsigned ? Ps : dn; var s, o, r; if (this.unsigned) { if (t.unsigned || (t = t.toUnsigned()), t.gt(this)) return Ps; if (t.gt(this.shru(1))) return Pf; r = Ps } else { if (this.eq(Ke)) { if (t.eq(Wo) || t.eq(Pu)) return Ke; if (t.eq(Ke)) return Wo; var i = this.shr(1); return s = i.div(t).shl(1), s.eq(dn) ? t.isNegative() ? Wo : Pu : (o = this.sub(t.mul(s)), r = s.add(o.div(t)), r) } else if (t.eq(Ke)) return this.unsigned ? Ps : dn; if (this.isNegative()) return t.isNegative() ? this.neg().div(t.neg()) : this.neg().div(t).neg(); if (t.isNegative()) return this.div(t.neg()).neg(); r = dn } for (o = this; o.gte(t);) { s = Math.max(1, Math.floor(o.toNumber() / t.toNumber())); for (var a = Math.ceil(Math.log(s) / Math.LN2), c = a <= 48 ? 1 : xc(2, a - 48), l = un(s), u = l.mul(t); u.isNegative() || u.gt(o);)s -= c, l = un(s, this.unsigned), u = l.mul(t); l.isZero() && (l = Wo), r = r.add(l), o = o.sub(u) } return r }, tt.div = tt.divide, tt.modulo = function (t) { if (Pe(t) || (t = vn(t)), ln) { var e = (this.unsigned ? ln.rem_u : ln.rem_s)(this.low, this.high, t.low, t.high); return Kt(e, ln.get_high(), this.unsigned) } return this.sub(this.div(t).mul(t)) }, tt.mod = tt.modulo, tt.rem = tt.modulo, tt.not = function () { return Kt(~this.low, ~this.high, this.unsigned) }, tt.and = function (t) { return Pe(t) || (t = vn(t)), Kt(this.low & t.low, this.high & t.high, this.unsigned) }, tt.or = function (t) { return Pe(t) || (t = vn(t)), Kt(this.low | t.low, this.high | t.high, this.unsigned) }, tt.xor = function (t) { return Pe(t) || (t = vn(t)), Kt(this.low ^ t.low, this.high ^ t.high, this.unsigned) }, tt.shiftLeft = function (t) { return Pe(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? Kt(this.low << t, this.high << t | this.low >>> 32 - t, this.unsigned) : Kt(0, this.low << t - 32, this.unsigned) }, tt.shl = tt.shiftLeft, tt.shiftRight = function (t) { return Pe(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? Kt(this.low >>> t | this.high << 32 - t, this.high >> t, this.unsigned) : Kt(this.high >> t - 32, this.high >= 0 ? 0 : -1, this.unsigned) }, tt.shr = tt.shiftRight, tt.shiftRightUnsigned = function (t) { if (Pe(t) && (t = t.toInt()), t &= 63, t === 0) return this; var e = this.high; if (t < 32) { var s = this.low; return Kt(s >>> t | e << 32 - t, e >>> t, this.unsigned) } else return t === 32 ? Kt(e, 0, this.unsigned) : Kt(e >>> t - 32, 0, this.unsigned) }, tt.shru = tt.shiftRightUnsigned, tt.shr_u = tt.shiftRightUnsigned, tt.toSigned = function () { return this.unsigned ? Kt(this.low, this.high, !1) : this }, tt.toUnsigned = function () { return this.unsigned ? this : Kt(this.low, this.high, !0) }, tt.toBytes = function (t) { return t ? this.toBytesLE() : this.toBytesBE() }, tt.toBytesLE = function () { var t = this.high, e = this.low; return [e & 255, e >>> 8 & 255, e >>> 16 & 255, e >>> 24, t & 255, t >>> 8 & 255, t >>> 16 & 255, t >>> 24] }, tt.toBytesBE = function () { var t = this.high, e = this.low; return [t >>> 24, t >>> 16 & 255, t >>> 8 & 255, t & 255, e >>> 24, e >>> 16 & 255, e >>> 8 & 255, e & 255] }, Pt.fromBytes = function (t, e, s) { return s ? Pt.fromBytesLE(t, e) : Pt.fromBytesBE(t, e) }, Pt.fromBytesLE = function (t, e) { return new Pt(t[0] | t[1] << 8 | t[2] << 16 | t[3] << 24, t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24, e) }, Pt.fromBytesBE = function (t, e) { return new Pt(t[4] << 24 | t[5] << 16 | t[6] << 8 | t[7], t[0] << 24 | t[1] << 16 | t[2] << 8 | t[3], e) }; const Bf = qI(Mf), nC = DI({ __proto__: null, default: Bf }, [Mf]);/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ks = Bf || nC; function yc(n) { return Ks.fromString(n, !0, 16) } const Hf = yc("c3a5c85c97cb3127"), Zs = yc("b492b66fbe98f273"), Ne = yc("9ae16a3b2f90404f"); function Ku(n) { return n.xor(n.shru(47)) } function _f(n, t, e) { const s = n.slice(t, t + e); return Ks.fromBytes(Array.from(s), !0, !0) } function Mt(n, t) { return _f(n, t, 8) } function Uf(n, t) { return _f(n, t, 4) } function pe(n, t) { return t === 0 ? n : n.shru(t).or(n.shl(64 - t)) } function hs(n, t, e = yc("9ddfea08eb382d69")) { let s = n.xor(t).mul(e); s = s.xor(s.shru(47)); let o = t.xor(s).mul(e); return o = o.xor(o.shru(47)), o = o.mul(e), o } function sC(n, t, e, s, o, r) { o = o.add(n), r = pe(r.add(o).add(s), 21); const i = o; return o = o.add(t), o = o.add(e), r = r.add(pe(o, 44)), [o.add(s), r.add(i)] } function Ic(n, t, e, s) { return sC(Mt(n, t), Mt(n, t + 8), Mt(n, t + 16), Mt(n, t + 24), e, s) } function oC(n, t = n.length) { if (t >= 8) { const e = Ne.add(t * 2), s = Mt(n, 0).add(Ne), o = Mt(n, t - 8), r = pe(o, 37).mul(e).add(s), i = pe(s, 25).add(o).mul(e); return hs(r, i, e) } if (t >= 4) { const e = Ne.add(t * 2), s = Uf(n, 0); return hs(s.shl(3).add(t), Uf(n, t - 4), e) } if (t > 0) { const e = n[0], s = n[t >> 1], o = n[t - 1], r = e + (s << 8), i = t + (o << 2); return Ku(Ne.mul(r).xor(Hf.mul(i))).mul(Ne) } return Ne } function rC(n, t = n.length) { const e = Ne.add(t * 2), s = Mt(n, 0).mul(Zs), o = Mt(n, 8), r = Mt(n, t - 8).mul(e), i = Mt(n, t - 16).mul(Ne); return hs(pe(s.add(o), 43).add(pe(r, 30)).add(i), s.add(pe(o.add(Ne), 18)).add(r), e) } function iC(n, t = n.length) { const e = Ne.add(t * 2), s = Mt(n, 0).mul(Ne), o = Mt(n, 8), r = Mt(n, t - 8).mul(e), i = Mt(n, t - 16).mul(Ne), a = pe(s.add(o), 43).add(pe(r, 30)).add(i), c = hs(a, s.add(pe(o.add(Ne), 18)).add(r), e), l = Mt(n, 16).mul(e), u = Mt(n, 24), d = a.add(Mt(n, t - 32)).mul(e), h = c.add(Mt(n, t - 24)).mul(e); return hs(pe(l.add(u), 43).add(pe(d, 30)).add(h), l.add(pe(u.add(s), 18)).add(d), e) } function aC(n, t = n.length) { const e = Ks.fromNumber(81, !0); if (t <= 32) return t <= 16 ? oC(n, t) : rC(n, t); if (t <= 64) return iC(n, t); let s = e, o = e.mul(Zs).add(113), r = Ku(o.mul(Ne).add(113)).mul(Ne), i = [Ks.UZERO, Ks.UZERO], a = [Ks.UZERO, Ks.UZERO]; s = s.mul(Ne).add(Mt(n, 0)); let c = 0; const l = (t - 1 >> 6) * 64, u = l + (t - 1 & 63) - 63; do s = pe(s.add(o).add(i[0]).add(Mt(n, c + 8)), 37).mul(Zs), o = pe(o.add(i[1]).add(Mt(n, c + 48)), 42).mul(Zs), s = s.xor(a[1]), o = o.add(i[0]).add(Mt(n, c + 40)), r = pe(r.add(a[0]), 33).mul(Zs), i = Ic(n, c, i[1].mul(Zs), s.add(a[0])), a = Ic(n, c + 32, r.add(a[1]), o.add(Mt(n, c + 16))), [r, s] = [s, r], c += 64; while (c !== l); const d = Zs.add(r.and(255).shl(1)); return c = u, a[0] = a[0].add(t - 1 & 63), i[0] = i[0].add(a[0]), a[0] = a[0].add(i[0]), s = pe(s.add(o).add(i[0]).add(Mt(n, c + 8)), 37).mul(d), o = pe(o.add(i[1]).add(Mt(n, c + 48)), 42).mul(d), s = s.xor(a[1].mul(9)), o = o.add(i[0].mul(9).add(Mt(n, c + 40))), r = pe(r.add(a[0]), 33).mul(d), i = Ic(n, c, i[1].mul(d), s.add(a[0])), a = Ic(n, c + 32, r.add(a[1]), o.add(Mt(n, c + 16))), [r, s] = [s, r], hs(hs(i[0], a[0], d).add(Ku(o).mul(Hf)).add(r), hs(i[1], a[1], d).add(s), d) }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ps(n, t) { return t === "string" ? fs(n) : Bs([n], t) } function cC(n, t) { return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool" } function Bs(n, t) { if (t === "string") throw new Error("Cannot convert a string[] to a TypedArray"); if (Array.isArray(n) && (n = Hs(n)), A().getBool("DEBUG") && zI(n, t), cC(n, t)) return n; if (t == null || t === "float32" || t === "complex64") return new Float32Array(n); if (t === "int32") return new Int32Array(n); if (t === "bool") { const e = new Uint8Array(n.length); for (let s = 0; s < e.length; ++s)Math.round(n[s]) !== 0 && (e[s] = 1); return e } else throw new Error(`Unknown data type ${t}`) } function Me() { return A().platform.now() } function fs(n, t = "utf-8") { return t = t || "utf-8", A().platform.encode(n, t) } function ms(n, t = "utf-8") { return t = t || "utf-8", A().platform.decode(n, t) } function Sn(n) { return A().platform.isTypedArray(n) } function Hs(n, t = [], e = !1) { if (t == null && (t = []), typeof n == "boolean" || typeof n == "number" || typeof n == "string" || Yl(n) || n == null || Sn(n) && e) t.push(n); else if (Array.isArray(n) || Sn(n)) for (let s = 0; s < n.length; ++s)Hs(n[s], t, e); else { let s = -1; for (const o of Object.keys(n)) /^([1-9]+[0-9]*|0)$/.test(o) && (s = Math.max(s, Number(o))); for (let o = 0; o <= s; o++)Hs(n[o], t, e) } return t }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class lC { constructor(t, e) { this.backendTimer = t, this.logger = e, e == null && (this.logger = new dC) } profileKernel(t, e, s) { let o; const r = () => { o = s() }; let i; const a = Me(); if (this.backendTimer.timerAvailable()) i = this.backendTimer.time(r); else { r(); for (const l of o) l.dataSync(); i = Promise.resolve({ kernelMs: Me() - a }) } if (A().getBool("CHECK_COMPUTATION_FOR_ERRORS")) for (let l = 0; l < o.length; l++) { const u = o[l]; u.data().then(d => { uC(d, u.dtype, t) }) } return { kernelName: t, outputs: o, inputs: e, timeMs: i.then(l => l.kernelMs), extraInfo: i.then(l => l.getExtraProfileInfo != null ? l.getExtraProfileInfo() : "") } } logKernelProfile(t) { const { kernelName: e, outputs: s, timeMs: o, inputs: r, extraInfo: i } = t; s.forEach(a => { Promise.all([a.data(), o, i]).then(c => { this.logger.logKernelProfile(e, a, c[0], c[1], r, c[2]) }) }) } } function uC(n, t, e) { if (t !== "float32") return !1; for (let s = 0; s < n.length; s++) { const o = n[s]; if (isNaN(o) || !isFinite(o)) return console.warn(`Found ${o} in the result of '${e}'`), !0 } return !1 } class dC { logKernelProfile(t, e, s, o, r, i) { const a = typeof o == "number" ? $o(`${o}ms`, 9) : o.error, c = $o(t, 25), l = e.rank, u = e.size, d = $o(e.shape.toString(), 14); let h = ""; for (const p in r) { const f = r[p]; if (f != null) { const m = f.shape || e.shape, g = m.length; h += `${p}: ${g}D ${g > 0 ? m : ""} ` } } console.log(`%c${c}	%c${a}	%c${l}D ${d}	%c${u}	%c${h}	%c${i}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue") } }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hC(n, t, e) { const s = {}, o = {}; for (let c = 0; c < t.length; c++)s[t[c].id] = !0; for (let c = 0; c < n.length; c++) { const l = n[c], u = l.inputs; for (const d in u) { const h = u[d]; let p = !1; for (let f = 0; f < t.length; f++)if (s[h.id]) { l.outputs.forEach(m => s[m.id] = !0), p = !0, o[l.id] = !0; break } if (p) break } } const r = {}; r[e.id] = !0; const i = {}; for (let c = n.length - 1; c >= 0; c--) { const l = n[c], u = l.inputs; for (let d = 0; d < l.outputs.length; d++)if (r[l.outputs[d].id]) { for (const h in u) r[u[h].id] = !0, i[l.id] = !0; break } } const a = []; for (let c = 0; c < n.length; c++) { const l = n[c]; if (o[l.id] && i[l.id]) { const u = {}; for (const h in l.inputs) { const p = l.inputs[h]; s[p.id] && (u[h] = p) } const d = Object.assign({}, l); d.inputs = u, d.outputs = l.outputs, a.push(d) } } return a } function pC(n, t, e, s) { for (let o = t.length - 1; o >= 0; o--) { const r = t[o], i = []; if (r.outputs.forEach(c => { const l = n[c.id]; l != null ? i.push(l) : i.push(null) }), r.gradient == null) throw new Error(`Cannot compute gradient: gradient function not found for ${r.kernelName}.`); const a = r.gradient(i); for (const c in r.inputs) { if (!(c in a)) throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(a)}.`); const l = e(() => a[c]()); if (l.dtype !== "float32") throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`); const u = r.inputs[c]; if (!Rt(l.shape, u.shape)) throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input '${c}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`); if (n[u.id] == null) n[u.id] = l; else { const d = n[u.id]; n[u.id] = s(d, l), d.dispose() } } } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Yf = 20, fi = 3, Zu = 7; function fC(n, t, e, s) {
        const o = ct(t), r = mC(n, t, e, o), i = t.length, a = Cc(n, t, e, o, r), c = ["Tensor"]; return s && (c.push(`  dtype: ${e}`), c.push(`  rank: ${i}`), c.push(`  shape: [${t}]`), c.push("  values:")), c.push(a.map(l => "    " + l).join(`
`)), c.join(`
`)
    } function mC(n, t, e, s) { const o = Z(t), r = s[s.length - 1], i = new Array(r).fill(0), a = t.length, c = e === "complex64" ? gi(n) : n; if (a > 1) for (let l = 0; l < o / r; l++) { const u = l * r; for (let d = 0; d < r; d++)i[d] = Math.max(i[d], mi(c[u + d], 0, e).length) } return i } function mi(n, t, e) { let s; return Array.isArray(n) ? s = `${parseFloat(n[0].toFixed(Zu))} + ${parseFloat(n[1].toFixed(Zu))}j` : br(n) ? s = `'${n}'` : e === "bool" ? s = Qf(n) : s = parseFloat(n.toFixed(Zu)).toString(), $o(s, t) } function Qf(n) { return n === 0 ? "false" : "true" } function Cc(n, t, e, s, o, r = !0) {
        const i = e === "complex64" ? 2 : 1, a = t[0], c = t.length; if (c === 0) { if (e === "complex64") { const m = gi(n); return [mi(m[0], 0, e)] } return e === "bool" ? [Qf(n[0])] : [n[0].toString()] } if (c === 1) { if (a > Yf) { const g = fi * i; let b = Array.from(n.slice(0, g)), x = Array.from(n.slice((a - fi) * i, a * i)); return e === "complex64" && (b = gi(b), x = gi(x)), ["[" + b.map((I, y) => mi(I, o[y], e)).join(", ") + ", ..., " + x.map((I, y) => mi(I, o[a - fi + y], e)).join(", ") + "]"] } return ["[" + (e === "complex64" ? gi(n) : Array.from(n)).map((g, b) => mi(g, o[b], e)).join(", ") + "]"] } const l = t.slice(1), u = s.slice(1), d = s[0] * i, h = []; if (a > Yf) { for (let m = 0; m < fi; m++) { const g = m * d, b = g + d; h.push(...Cc(n.slice(g, b), l, e, u, o, !1)) } h.push("..."); for (let m = a - fi; m < a; m++) { const g = m * d, b = g + d; h.push(...Cc(n.slice(g, b), l, e, u, o, m === a - 1)) } } else for (let m = 0; m < a; m++) { const g = m * d, b = g + d; h.push(...Cc(n.slice(g, b), l, e, u, o, m === a - 1)) } const p = c === 2 ? "," : ""; h[0] = "[" + (a > 0 ? h[0] + p : ""); for (let m = 1; m < h.length - 1; m++)h[m] = " " + h[m] + p; let f = `,
`; for (let m = 2; m < c; m++)f += `
`; return h[h.length - 1] = " " + h[h.length - 1] + "]" + (r ? "" : f), h
    } function gi(n) { const t = []; for (let e = 0; e < n.length; e += 2)t.push([n[e], n[e + 1]]); return t }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class ke { constructor(t, e, s) { if (this.dtype = e, this.shape = t.slice(), this.size = Z(t), s != null) { const o = s.length; v(o === this.size, () => `Length of values '${o}' does not match the size inferred by the shape '${this.size}'.`) } if (e === "complex64") throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag)."); this.values = s || ne(e, this.size), this.strides = ct(t) } set(t, ...e) { e.length === 0 && (e = [0]), v(e.length === this.rank, () => `The number of provided coordinates (${e.length}) must match the rank (${this.rank})`); const s = this.locToIndex(e); this.values[s] = t } get(...t) { t.length === 0 && (t = [0]); let e = 0; for (const o of t) { if (o < 0 || o >= this.shape[e]) { const r = `Requested out of range element at ${t}.   Buffer shape=${this.shape}`; throw new Error(r) } e++ } let s = t[t.length - 1]; for (let o = 0; o < t.length - 1; ++o)s += this.strides[o] * t[o]; return this.values[s] } locToIndex(t) { if (this.rank === 0) return 0; if (this.rank === 1) return t[0]; let e = t[t.length - 1]; for (let s = 0; s < t.length - 1; ++s)e += this.strides[s] * t[s]; return e } indexToLoc(t) { if (this.rank === 0) return []; if (this.rank === 1) return [t]; const e = new Array(this.shape.length); for (let s = 0; s < e.length - 1; ++s)e[s] = Math.floor(t / this.strides[s]), t -= e[s] * this.strides[s]; return e[e.length - 1] = t, e } get rank() { return this.shape.length } toTensor() { return kn().makeTensor(this.values, this.shape, this.dtype) } } let kn = null, Mo = null; function gC(n) { kn = n } function bC(n) { Mo = n } class se { constructor(t, e, s, o) { this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = e || "float32", this.size = Z(t), this.strides = ct(t), this.dataId = s, this.id = o, this.rankType = this.rank < 5 ? this.rank.toString() : "higher" } get rank() { return this.shape.length } async buffer() { const t = await this.data(); return Mo.buffer(this.shape, this.dtype, t) } bufferSync() { return Mo.buffer(this.shape, this.dtype, this.dataSync()) } async array() { const t = await this.data(); return wn(this.shape, t, this.dtype === "complex64") } arraySync() { return wn(this.shape, this.dataSync(), this.dtype === "complex64") } async data() { this.throwIfDisposed(); const t = kn().read(this.dataId); if (this.dtype === "string") { const e = await t; try { return e.map(s => ms(s)) } catch { throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().") } } return t } dataToGPU(t) { return this.throwIfDisposed(), kn().readToGPU(this.dataId, t) } dataSync() { this.throwIfDisposed(); const t = kn().readSync(this.dataId); if (this.dtype === "string") try { return t.map(e => ms(e)) } catch { throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().") } return t } async bytes() { this.throwIfDisposed(); const t = await kn().read(this.dataId); return this.dtype === "string" ? t : new Uint8Array(t.buffer) } dispose() { this.isDisposed || (kn().disposeTensor(this), this.isDisposedInternal = !0) } get isDisposed() { return this.isDisposedInternal } throwIfDisposed() { if (this.isDisposed) throw new Error("Tensor is disposed.") } print(t = !1) { return Mo.print(this, t) } clone() { return this.throwIfDisposed(), Mo.clone(this) } toString(t = !1) { const e = this.dataSync(); return fC(e, this.shape, this.dtype, t) } cast(t) { return this.throwIfDisposed(), Mo.cast(this, t) } variable(t = !0, e, s) { return this.throwIfDisposed(), kn().makeVariable(this, t, e, s) } } Object.defineProperty(se, Symbol.hasInstance, { value: n => !!n && n.data != null && n.dataSync != null && n.throwIfDisposed != null }); function P() { return Jl("Tensor", () => se) } P(); class wc extends se { constructor(t, e, s, o) { super(t.shape, t.dtype, t.dataId, o), this.trainable = e, this.name = s } assign(t) { if (t.dtype !== this.dtype) throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`); if (!Rt(t.shape, this.shape)) throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`); kn().disposeTensor(this), this.dataId = t.dataId, kn().incRef(this, null) } dispose() { kn().disposeVariable(this), this.isDisposedInternal = !0 } } Object.defineProperty(wc, Symbol.hasInstance, { value: n => n instanceof se && n.assign != null && n.assign instanceof Function });/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */var Jf; (function (n) { n.R0 = "R0", n.R1 = "R1", n.R2 = "R2", n.R3 = "R3", n.R4 = "R4", n.R5 = "R5", n.R6 = "R6" })(Jf || (Jf = {})); var Bu; (function (n) { n.float32 = "float32", n.int32 = "int32", n.bool = "int32", n.complex64 = "complex64" })(Bu || (Bu = {})); var Hu; (function (n) { n.float32 = "float32", n.int32 = "int32", n.bool = "bool", n.complex64 = "complex64" })(Hu || (Hu = {})); var _u; (function (n) { n.float32 = "float32", n.int32 = "float32", n.bool = "float32", n.complex64 = "complex64" })(_u || (_u = {})); var Uu; (function (n) { n.float32 = "complex64", n.int32 = "complex64", n.bool = "complex64", n.complex64 = "complex64" })(Uu || (Uu = {})); const xC = { float32: _u, int32: Bu, bool: Hu, complex64: Uu }; function Ze(n, t) { if (n === "string" || t === "string") { if (n === "string" && t === "string") return "string"; throw new Error(`Can not upcast ${n} with ${t}`) } return xC[n][t] } function Yu(n) { return Ze(n, "int32") }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qt(n, t) { if (n.dtype === t.dtype) return [n, t]; const e = Ze(n.dtype, t.dtype); return [n.cast(e), t.cast(e)] } function jf(n) { const t = []; return qf(n, t, new Set), t } function qf(n, t, e) { if (n == null) return; if (n instanceof se) { t.push(n); return } if (!yC(n)) return; const s = n; for (const o in s) { const r = s[o]; e.has(r) || (e.add(r), qf(r, t, e)) } } function yC(n) { return Array.isArray(n) || typeof n == "object" }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Qu(n) { return n.kernelName != null } class tm { constructor() { this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = new WeakMap, this.profiling = !1, this.activeProfile = { newBytes: 0, newTensors: 0, peakBytes: 0, kernels: [], result: null, get kernelNames() { return Array.from(new Set(this.kernels.map(t => t.name))) } } } dispose() { for (const t in this.registeredVariables) this.registeredVariables[t].dispose() } } class Fo { constructor(t) { this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new tm } async ready() { if (this.pendingBackendInit != null) return this.pendingBackendInit.then(() => { }); if (this.backendInstance != null) return; const t = this.getSortedBackends(); for (let e = 0; e < t.length; e++) { const s = t[e]; if (await this.initializeBackend(s).success) { await this.setBackend(s); return } } throw new Error("Could not initialize any backends, all backend initializations failed.") } get backend() { if (this.pendingBackendInit != null) throw new Error(`Backend '${this.backendName}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`); if (this.backendInstance == null) { const { name: t, asyncInit: e } = this.initializeBackendsAndReturnBest(); if (e) throw new Error(`The highest priority backend '${t}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`); this.setBackend(t) } return this.backendInstance } backendNames() { return Object.keys(this.registryFactory) } findBackend(t) { if (!(t in this.registry)) if (t in this.registryFactory) { const { asyncInit: e } = this.initializeBackend(t); if (e) return null } else return null; return this.registry[t] } findBackendFactory(t) { return t in this.registryFactory ? this.registryFactory[t].factory : null } registerBackend(t, e, s = 1) { return t in this.registryFactory ? (Qe(`${t} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[t] = { factory: e, priority: s }, !0) } async setBackend(t) { if (this.registryFactory[t] == null) throw new Error(`Backend name '${t}' not found in registry`); if (this.backendName = t, this.registry[t] == null) { this.backendInstance = null; const { success: e, asyncInit: s } = this.initializeBackend(t); if (!(s ? await e : e)) return !1 } return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new lC(this.backendInstance), !0 } setupRegisteredKernels() { Df(this.backendName).forEach(e => { e.setupFunc != null && e.setupFunc(this.backendInstance) }) } disposeRegisteredKernels(t) { Df(t).forEach(s => { s.disposeFunc != null && s.disposeFunc(this.registry[t]) }) } initializeBackend(t) { const e = this.registryFactory[t]; if (e == null) throw new Error(`Cannot initialize backend ${t}, no registration found.`); try { const s = e.factory(); if (s && !(s instanceof Al) && typeof s.then == "function") { const o = ++this.pendingBackendInitId, r = s.then(i => o < this.pendingBackendInitId ? !1 : (this.registry[t] = i, this.pendingBackendInit = null, !0)).catch(i => (o < this.pendingBackendInitId || (this.pendingBackendInit = null, Qe(`Initialization of backend ${t} failed`), Qe(i.stack || i.message)), !1)); return this.pendingBackendInit = r, { success: r, asyncInit: !0 } } else return this.registry[t] = s, { success: !0, asyncInit: !1 } } catch (s) { return Qe(`Initialization of backend ${t} failed`), Qe(s.stack || s.message), { success: !1, asyncInit: !1 } } } removeBackend(t) { if (!(t in this.registryFactory)) throw new Error(`${t} backend not found in registry`); this.backendName === t && this.pendingBackendInit != null && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null) } getSortedBackends() { if (Object.keys(this.registryFactory).length === 0) throw new Error("No backend found in registry."); return Object.keys(this.registryFactory).sort((t, e) => this.registryFactory[e].priority - this.registryFactory[t].priority) } initializeBackendsAndReturnBest() { const t = this.getSortedBackends(); for (let e = 0; e < t.length; e++) { const s = t[e], { success: o, asyncInit: r } = this.initializeBackend(s); if (r || o) return { name: s, asyncInit: r } } throw new Error("Could not initialize any backends, all backend initializations failed.") } moveData(t, e) { const s = this.state.tensorInfo.get(e), o = s.backend, r = this.readSync(e), i = o.refCount(e); o.disposeData(e, !0), s.backend = t, t.move(e, r, s.shape, s.dtype, i), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++ } tidy(t, e) { let s = null; if (e == null) { if (typeof t != "function") throw new Error("Please provide a function to tidy()"); e = t } else { if (typeof t != "string" && !(t instanceof String)) throw new Error("When calling with two arguments, the first argument to tidy() must be a string"); if (typeof e != "function") throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function"); s = t } let o; return this.scopedRun(() => this.startScope(s), () => this.endScope(o), () => (o = e(), o instanceof Promise && console.error("Cannot return a Promise inside of tidy."), o)) } scopedRun(t, e, s) { t(); try { const o = s(); return e(), o } catch (o) { throw e(), o } } nextTensorId() { return Fo.nextTensorId++ } nextVariableId() { return Fo.nextVariableId++ } clone(t) { const e = L.runKernel(Xr, { x: t }), s = { x: t }, o = i => ({ x: () => { const a = "float32", c = { x: i }, l = { dtype: a }; return L.runKernel(Tr, c, l) } }), r = []; return this.addTapeNode(this.state.activeScope.name, s, [e], o, r, {}), e } runKernel(t, e, s) { if (this.backendName == null && this.backend, !(Au(t, this.backendName) != null)) throw new Error(`Kernel '${t}' not registered for backend '${this.backendName}'`); return this.runKernelFunc({ kernelName: t, inputs: e, attrs: s }) } shouldCheckForMemLeaks() { return this.ENV.getBool("IS_TEST") } checkKernelForMemLeak(t, e, s) { const o = this.backend.numDataIds(); let r = 0; s.forEach(c => { r += c.dtype === "complex64" ? 3 : 1 }); const i = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], a = o - e - r - i; if (a > 0) throw new Error(`Backend '${this.backendName}' has an internal memory leak (${a} data ids) after running '${t}'`) } runKernelFunc(t) { let e, s = []; const o = this.isTapeOn(), r = this.state.numBytes, i = this.state.numTensors; this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0); let a; this.backendName == null && this.backend; let c; const l = Qu(t) ? t.kernelName : this.state.activeScope != null ? this.state.activeScope.name : ""; if (Qu(t)) { const { kernelName: f, inputs: m, attrs: g } = t; this.backendName == null && this.backend; const b = Au(f, this.backendName); v(b != null, () => `Cannot find registered kernel '${f}' for backend '${this.backendName}'`), a = () => { const x = this.backend.numDataIds(); c = b.kernelFunc({ inputs: m, attrs: g, backend: this.backend }); const I = Array.isArray(c) ? c : [c]; this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(f, x, I); const y = I.map(C => C.rank != null ? C : this.makeTensorFromTensorInfo(C)); if (o) { const C = this.getTensorsForGradient(f, m, y); s = this.saveTensorsForBackwardMode(C) } return y } } else { const { forwardFunc: f } = t, m = g => { o && (s = g.map(b => this.keep(this.clone(b)))) }; a = () => { const g = this.backend.numDataIds(); c = this.tidy(() => f(this.backend, m)); const b = Array.isArray(c) ? c : [c]; return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(l, g, b), b } } const { inputs: u, attrs: d } = t, h = Qu(t) ? null : t.backwardsFunc; let p; return this.scopedRun(() => this.state.kernelDepth++, () => this.state.kernelDepth--, () => { !this.ENV.getBool("DEBUG") && !this.state.profiling ? e = a() : (p = this.profiler.profileKernel(l, u, () => a()), this.ENV.getBool("DEBUG") && this.profiler.logKernelProfile(p), e = p.outputs) }), o && this.addTapeNode(l, u, e, h, s, d), this.state.profiling && this.state.activeProfile.kernels.push({ name: l, bytesAdded: this.state.numBytes - r, totalBytesSnapshot: this.state.numBytes, tensorsAdded: this.state.numTensors - i, totalTensorsSnapshot: this.state.numTensors, inputShapes: Object.keys(u).map(f => u[f] != null ? u[f].shape : null), outputShapes: e.map(f => f.shape), kernelTimeMs: p.timeMs, extraInfo: p.extraInfo }), Array.isArray(c) ? e : e[0] } saveTensorsForBackwardMode(t) { return t.map(s => this.keep(this.clone(s))) } getTensorsForGradient(t, e, s) { const o = Ef(t); if (o != null) { const r = o.inputsToSave || [], i = o.outputsToSave || []; let a; o.saveAllInputs ? (v(Array.isArray(e), () => "saveAllInputs is true, expected inputs to be an array."), a = Object.keys(e).map(l => e[l])) : a = r.map(l => e[l]); const c = s.filter((l, u) => i[u]); return a.concat(c) } return [] } makeTensor(t, e, s, o) { if (t == null) throw new Error("Values passed to engine.makeTensor() are null"); s = s || "float32", o = o || this.backend; let r = t; s === "string" && br(t[0]) && (r = t.map(c => fs(c))); const i = o.write(r, e, s), a = new se(e, s, i, this.nextTensorId()); if (this.trackTensor(a, o), s === "string") { const c = this.state.tensorInfo.get(i), l = AI(r); this.state.numBytes += l - c.bytes, c.bytes = l } return a } makeTensorFromDataId(t, e, s, o) { s = s || "float32"; const r = { dataId: t, shape: e, dtype: s }; return this.makeTensorFromTensorInfo(r, o) } makeTensorFromTensorInfo(t, e) { const { dataId: s, shape: o, dtype: r } = t, i = new se(o, r, s, this.nextTensorId()); return this.trackTensor(i, e), i } makeVariable(t, e = !0, s, o) { s = s || this.nextVariableId().toString(), o != null && o !== t.dtype && (t = t.cast(o)); const r = new wc(t, e, s, this.nextTensorId()); if (this.state.registeredVariables[r.name] != null) throw new Error(`Variable with name ${r.name} was already registered`); return this.state.registeredVariables[r.name] = r, this.incRef(r, this.backend), r } trackTensor(t, e) { this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++; let s = 0; t.dtype !== "complex64" && t.dtype !== "string" && (s = t.size * fa(t.dtype)), this.state.numBytes += s, this.state.tensorInfo.has(t.dataId) || (this.state.numDataBuffers++, this.state.tensorInfo.set(t.dataId, { backend: e || this.backend, dtype: t.dtype, shape: t.shape, bytes: s })), t instanceof wc || this.track(t) } incRef(t, e) { this.trackTensor(t, e), this.backend.incRef(t.dataId) } removeDataId(t, e) { this.state.tensorInfo.has(t) && this.state.tensorInfo.get(t).backend === e && (this.state.tensorInfo.delete(t), this.state.numDataBuffers--) } disposeTensor(t) { if (!this.state.tensorInfo.has(t.dataId)) return; const e = this.state.tensorInfo.get(t.dataId); if (this.state.numTensors--, t.dtype === "string" && (this.state.numStringTensors--, this.state.numBytes -= e.bytes), t.dtype !== "complex64" && t.dtype !== "string") { const s = t.size * fa(t.dtype); this.state.numBytes -= s } e.backend.disposeData(t.dataId) && this.removeDataId(t.dataId, e.backend) } disposeVariables() { for (const t in this.state.registeredVariables) { const e = this.state.registeredVariables[t]; this.disposeVariable(e) } } disposeVariable(t) { this.disposeTensor(t), this.state.registeredVariables[t.name] != null && delete this.state.registeredVariables[t.name] } memory() { const t = this.backend.memory(); return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = !0, t.reasons == null && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t } async profile(t) { this.state.profiling = !0; const e = this.state.numBytes, s = this.state.numTensors; this.state.activeProfile.kernels = [], this.state.activeProfile.result = await t(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max(...this.state.activeProfile.kernels.map(o => o.totalBytesSnapshot)), this.state.activeProfile.newBytes = this.state.numBytes - e, this.state.activeProfile.newTensors = this.state.numTensors - s; for (const o of this.state.activeProfile.kernels) o.kernelTimeMs = await o.kernelTimeMs, o.extraInfo = await o.extraInfo; return this.state.activeProfile } isTapeOn() { return this.state.gradientDepth > 0 && this.state.kernelDepth === 0 } addTapeNode(t, e, s, o, r, i) { const a = { id: this.state.nextTapeNodeId++, kernelName: t, inputs: e, outputs: s, saved: r }, c = Ef(t); c != null && (o = c.gradFunc), o != null && (a.gradient = l => (l = l.map((u, d) => { if (u == null) { const h = s[d], p = Se(h.size, h.dtype); return this.makeTensor(p, h.shape, h.dtype) } return u }), o(l.length > 1 ? l : l[0], r, i))), this.state.activeTape.push(a) } keep(t) { return t.kept = !0, t } startTape() { this.state.gradientDepth === 0 && (this.state.activeTape = []), this.state.gradientDepth++ } endTape() { this.state.gradientDepth-- } startScope(t) { const e = { track: [], name: "unnamed scope", id: this.state.nextScopeId++ }; t && (e.name = t), this.state.scopeStack.push(e), this.state.activeScope = e } endScope(t) { const e = jf(t), s = new Set(e.map(r => r.id)); for (let r = 0; r < this.state.activeScope.track.length; r++) { const i = this.state.activeScope.track[r]; !i.kept && !s.has(i.id) && i.dispose() } const o = this.state.scopeStack.pop(); this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], e.forEach(r => { !r.kept && r.scopeId === o.id && this.track(r) }) } gradients(t, e, s, o = !1) { if (v(e.length > 0, () => "gradients() received an empty list of xs."), s != null && s.dtype !== "float32") throw new Error(`dy must have 'float32' dtype, but has '${s.dtype}'`); const r = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", t)); v(r instanceof se, () => "The result y returned by f() must be a tensor."); const i = hC(this.state.activeTape, e, r); if (!o && i.length === 0 && e.length > 0) throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y."); return this.tidy("backward", () => { const a = {}; a[r.id] = s ?? IC(r.shape), pC(a, i, l => this.tidy(l), CC); const c = e.map(l => a[l.id]); return this.state.gradientDepth === 0 && (this.state.activeTape.forEach(l => { for (const u of l.saved) u.dispose() }), this.state.activeTape = null), { value: r, grads: c } }) } customGrad(t) { return v(Hl(t), () => "The f passed in customGrad(f) must be a function."), (...e) => { v(e.every(a => a instanceof se), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors"); let s; const o = {}; e.forEach((a, c) => { o[c] = a }); const r = (a, c) => (s = t(...e, c), v(s.value instanceof se, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), v(Hl(s.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), s.value), i = (a, c) => { const l = s.gradFunc(a, c), u = Array.isArray(l) ? l : [l]; v(u.length === e.length, () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."), v(u.every(h => h instanceof se), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."); const d = {}; return u.forEach((h, p) => { d[p] = () => h }), d }; return this.runKernelFunc({ forwardFunc: r, backwardsFunc: i, inputs: o }) } } readSync(t) { return this.state.tensorInfo.get(t).backend.readSync(t) } read(t) { return this.state.tensorInfo.get(t).backend.read(t) } readToGPU(t, e) { return this.state.tensorInfo.get(t).backend.readToGPU(t, e) } async time(t) { const e = Me(), s = await this.backend.time(t); return s.wallMs = Me() - e, s } track(t) { return this.state.activeScope != null && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t } get registeredVariables() { return this.state.registeredVariables } reset() { this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new tm; for (const t in this.registry) this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]; this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null } } Fo.nextTensorId = 0, Fo.nextVariableId = 0; function IC(n) { const t = Ul(Z(n), "float32"); return L.makeTensor(t, n, "float32") } function em() { const n = uf(); if (n._tfengine == null) { const t = new KI(n); n._tfengine = new Fo(t) } return _I(n._tfengine.ENV), gC(() => n._tfengine), n._tfengine } const L = em(); function CC(n, t) { const e = { a: n, b: t }; return L.runKernel(Lo, e) }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function wC() { return typeof navigator < "u" && navigator != null } function nm(n) { if (n || wC()) { if (n || (n = navigator), n.product === "ReactNative") return !0; const t = n.userAgent || n.vendor || (typeof window < "u" ? window.opera : ""); if (!t) { const e = n; return e.userAgentData && e.userAgentData.mobile } return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0, 4)) } return !1 } function sm() { return typeof window < "u" && window.document != null || typeof WorkerGlobalScope < "u" }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const je = A(); je.registerFlag("DEBUG", () => !1, n => { n && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.") }), je.registerFlag("IS_BROWSER", () => sm()), je.registerFlag("IS_NODE", () => typeof process < "u" && typeof process.versions < "u" && typeof process.versions.node < "u"), je.registerFlag("IS_CHROME", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)), je.registerFlag("PROD", () => !1), je.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", () => je.getBool("DEBUG")), je.registerFlag("DEPRECATION_WARNINGS_ENABLED", () => !0), je.registerFlag("IS_TEST", () => !1), je.registerFlag("CHECK_COMPUTATION_FOR_ERRORS", () => !0), je.registerFlag("WRAP_TO_IMAGEBITMAP", () => !1), je.registerFlag("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU", () => !1), je.registerFlag("USE_SETTIMEOUTCUSTOM", () => !1);/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bi(n, t) { let e = n; if (Sn(n)) return t === "string" ? [] : [n.length]; if (typeof n == "object") { if ("texture" in n) { const r = n.channels || "RGBA"; return [n.height, n.width * r.length] } else if ("buffer" in n && !(n.buffer instanceof ArrayBuffer)) return [n.buffer.size / (t == null ? 4 : fa(t))] } if (!Array.isArray(n)) return []; const o = []; for (; Array.isArray(e) || Sn(e) && t !== "string";)o.push(e.length), e = e[0]; return Array.isArray(n) && A().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && om(n, o, []), o } function om(n, t, e) { if (e = e || [], !Array.isArray(n) && !Sn(n)) { v(t.length === 0, () => `Element arr[${e.join("][")}] is a primitive, but should be an array/TypedArray of ${t[0]} elements`); return } v(t.length > 0, () => `Element arr[${e.join("][")}] should be a primitive, but is an array of ${n.length} elements`), v(n.length === t[0], () => `Element arr[${e.join("][")}] should have ${t[0]} elements, but has ${n.length} elements`); const s = t.slice(1); for (let o = 0; o < n.length; ++o)om(n[o], s, e.concat(o)) } function rm(n, t, e, s) { if (n !== "string_or_numeric") { if (n == null) throw new Error("Expected dtype cannot be null."); if (n !== "numeric" && n !== t || n === "numeric" && t === "string") throw new Error(`Argument '${e}' passed to '${s}' must be ${n} tensor, but got ${t} tensor`) } } function N(n, t, e, s = "numeric") { if (n instanceof se) return rm(s, n.dtype, t, e), n; let o = xr(n); if (o !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (o = s), rm(s, o, t, e), n == null || !Sn(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") { const c = n == null ? "null" : n.constructor.name; throw new Error(`Argument '${t}' passed to '${e}' must be a Tensor or TensorLike, but got '${c}'`) } const r = bi(n, o); !Sn(n) && !Array.isArray(n) && (n = [n]); const a = o !== "string" ? Bs(n, o) : Hs(n, [], !0); return L.makeTensor(a, r, o) } function im(n, t, e, s = "numeric") { if (!Array.isArray(n)) throw new Error(`Argument ${t} passed to ${e} must be a \`Tensor[]\` or \`TensorLike[]\``); return n.map((r, i) => N(r, `${t}[${i}]`, e, s)) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const vC = "__op"; function W(n) { const t = Object.keys(n); if (t.length !== 1) throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`); let e = t[0]; const s = n[e]; e.endsWith("_") && (e = e.substring(0, e.length - 1)), e = e + vC; const o = (...r) => { L.startScope(e); try { const i = s(...r); return Yl(i) && console.error("Cannot return a Promise inside of tidy."), L.endScope(i), i } catch (i) { throw L.endScope(null), i } }; return Object.defineProperty(o, "name", { value: e, configurable: !0 }), o }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function SC(n, t) { const e = N(n, "real", "complex"), s = N(t, "imag", "complex"); Pl(e.shape, s.shape, `real and imag shapes, ${e.shape} and ${s.shape}, must match in call to tf.complex().`); const o = { real: e, imag: s }; return L.runKernel(ou, o) } const Vo = W({ complex_: SC });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function xi(n, t, e, s) { if (s == null) s = xr(n); else if (s === "complex64") throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag)."); if (typeof n == "object" && ("texture" in n || "buffer" in n && !(n.buffer instanceof ArrayBuffer))) { if (s !== "float32" && s !== "int32") throw new Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${s}.`); return L.backend.createTensorFromGPUData(n, t || e, s) } if (!Sn(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray"); if (t != null) { jn(t); const o = Z(t), r = Z(e); v(o === r, () => `Based on the provided shape, [${t}], the tensor should have ${o} values but has ${r}`); for (let i = 0; i < e.length; ++i) { const a = e[i], c = i === e.length - 1 ? a !== Z(t.slice(i)) : !0; v(e[i] === t[i] || !c, () => `Error creating a new Tensor. Inferred shape (${e}) does not match the provided shape (${t}). `) } } return !Sn(n) && !Array.isArray(n) && (n = [n]), t = t || e, n = s !== "string" ? Bs(n, s) : Hs(n, [], !0), L.makeTensor(n, t, s) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qe(n, t, e) { const s = bi(n, e); return xi(n, t, s, e) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const am = 4; async function cm(n, t) { const e = [], s = [], o = Array.isArray(n) ? n.map(i => i.name) : Object.keys(n); for (let i = 0; i < o.length; ++i) { const a = o[i], c = Array.isArray(n) ? n[i].tensor : n[a]; if (c.dtype !== "float32" && c.dtype !== "int32" && c.dtype !== "bool" && c.dtype !== "string" && c.dtype !== "complex64") throw new Error(`Unsupported dtype in weight '${a}': ${c.dtype}`); const l = { name: a, shape: c.shape, dtype: c.dtype }; if (c.dtype === "string") { const u = new Promise(async d => { const h = await c.bytes(), p = h.reduce((g, b) => g + b.length, 0) + am * h.length, f = new Uint8Array(p); let m = 0; for (let g = 0; g < h.length; g++) { const b = h[g], x = new Uint8Array(new Uint32Array([b.length]).buffer); f.set(x, m), m += am, f.set(b, m), m += b.length } d(f) }); s.push(u) } else s.push(c.data()); t != null && (l.group = t), e.push(l) } const r = await Promise.all(s); return { data: kC(r), specs: e } } function kC(n) { if (n === null) throw new Error(`Invalid input value: ${JSON.stringify(n)}`); let t = 0; const e = []; n.forEach(r => { if (t += r.byteLength, e.push(r.byteLength === r.buffer.byteLength ? r : new r.constructor(r)), !(r instanceof Float32Array || r instanceof Int32Array || r instanceof Uint8Array)) throw new Error(`Unsupported TypedArray subtype: ${r.constructor.name}`) }); const s = new Uint8Array(t); let o = 0; return e.forEach(r => { s.set(new Uint8Array(r.buffer), o), o += r.byteLength }), s.buffer } const Ju = typeof Buffer < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u"); function lm(n) { return Ju ? Buffer.byteLength(n) : new Blob([n]).size } function TC(n) { if (Ju) return Buffer.from(n).toString("base64"); const t = new Uint8Array(n); let e = ""; for (let s = 0, o = t.length; s < o; s++)e += String.fromCharCode(t[s]); return btoa(e) } function NC(n) { if (Ju) { const s = Buffer.from(n, "base64"); return s.buffer.slice(s.byteOffset, s.byteOffset + s.byteLength) } const t = atob(n), e = new Uint8Array(t.length); for (let s = 0; s < t.length; ++s)e.set([t.charCodeAt(s)], s); return e.buffer } function RC(n) { if (n.length === 1) return n[0]; let t = 0; n.forEach(o => { t += o.byteLength }); const e = new Uint8Array(t); let s = 0; return n.forEach(o => { e.set(new Uint8Array(o), s), s += o.byteLength }), e.buffer } function um(n) { if (n.modelTopology instanceof ArrayBuffer) throw new Error("Expected JSON model topology, received ArrayBuffer."); return { dateSaved: new Date, modelTopologyType: "JSON", modelTopologyBytes: n.modelTopology == null ? 0 : lm(JSON.stringify(n.modelTopology)), weightSpecsBytes: n.weightSpecs == null ? 0 : lm(JSON.stringify(n.weightSpecs)), weightDataBytes: n.weightData == null ? 0 : n.weightData.byteLength } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Re { constructor() { this.saveRouters = [], this.loadRouters = [] } static getInstance() { return Re.instance == null && (Re.instance = new Re), Re.instance } static registerSaveRouter(t) { Re.getInstance().saveRouters.push(t) } static registerLoadRouter(t) { Re.getInstance().loadRouters.push(t) } static getSaveHandlers(t) { return Re.getHandlers(t, "save") } static getLoadHandlers(t, e) { return Re.getHandlers(t, "load", e) } static getHandlers(t, e, s) { const o = []; return (e === "load" ? Re.getInstance().loadRouters : Re.getInstance().saveRouters).forEach(i => { const a = i(t, s); a !== null && o.push(a) }), o } } const $C = n => Re.getSaveHandlers(n);/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ju = "tensorflowjs", qu = 1, _s = "models_store", gs = "model_info_store"; function dm() { if (!A().getBool("IS_BROWSER")) throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser."); const n = typeof window > "u" ? self : window, t = n.indexedDB || n.mozIndexedDB || n.webkitIndexedDB || n.msIndexedDB || n.shimIndexedDB; if (t == null) throw new Error("The current browser does not appear to support IndexedDB."); return t } function td(n) { const t = n.result; t.createObjectStore(_s, { keyPath: "modelPath" }), t.createObjectStore(gs, { keyPath: "modelPath" }) } class Us { constructor(t) { if (this.indexedDB = dm(), t == null || !t) throw new Error("For IndexedDB, modelPath must not be null, undefined or empty."); this.modelPath = t } async save(t) { if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet."); return this.databaseAction(this.modelPath, t) } async load() { return this.databaseAction(this.modelPath) } databaseAction(t, e) { return new Promise((s, o) => { const r = this.indexedDB.open(ju, qu); r.onupgradeneeded = () => td(r), r.onsuccess = () => { const i = r.result; if (e == null) { const a = i.transaction(_s, "readonly"), l = a.objectStore(_s).get(this.modelPath); l.onsuccess = () => { if (l.result == null) return i.close(), o(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`)); s(l.result.modelArtifacts) }, l.onerror = u => (i.close(), o(l.error)), a.oncomplete = () => i.close() } else { const a = um(e), c = i.transaction(gs, "readwrite"); let l = c.objectStore(gs); const u = l.put({ modelPath: this.modelPath, modelArtifactsInfo: a }); let d; u.onsuccess = () => { d = i.transaction(_s, "readwrite"); const p = d.objectStore(_s).put({ modelPath: this.modelPath, modelArtifacts: e, modelArtifactsInfo: a }); p.onsuccess = () => s({ modelArtifactsInfo: a }), p.onerror = f => { l = c.objectStore(gs); const m = l.delete(this.modelPath); m.onsuccess = () => (i.close(), o(p.error)), m.onerror = g => (i.close(), o(p.error)) } }, u.onerror = h => (i.close(), o(u.error)), c.oncomplete = () => { d == null ? i.close() : d.oncomplete = () => i.close() } } }, r.onerror = i => o(r.error) }) } } Us.URL_SCHEME = "indexeddb://"; const hm = n => A().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(Us.URL_SCHEME) ? GC(n.slice(Us.URL_SCHEME.length)) : null; Re.registerSaveRouter(hm), Re.registerLoadRouter(hm); function GC(n) { return new Us(n) } function LC(n) { return n.startsWith(Us.URL_SCHEME) ? n.slice(Us.URL_SCHEME.length) : n } class EC { constructor() { this.indexedDB = dm() } async listModels() { return new Promise((t, e) => { const s = this.indexedDB.open(ju, qu); s.onupgradeneeded = () => td(s), s.onsuccess = () => { const o = s.result, r = o.transaction(gs, "readonly"), a = r.objectStore(gs).getAll(); a.onsuccess = () => { const c = {}; for (const l of a.result) c[l.modelPath] = l.modelArtifactsInfo; t(c) }, a.onerror = c => (o.close(), e(a.error)), r.oncomplete = () => o.close() }, s.onerror = o => e(s.error) }) } async removeModel(t) { return t = LC(t), new Promise((e, s) => { const o = this.indexedDB.open(ju, qu); o.onupgradeneeded = () => td(o), o.onsuccess = () => { const r = o.result, i = r.transaction(gs, "readwrite"), a = i.objectStore(gs), c = a.get(t); let l; c.onsuccess = () => { if (c.result == null) return r.close(), s(new Error(`Cannot find model with path '${t}' in IndexedDB.`)); { const u = a.delete(t), d = () => { l = r.transaction(_s, "readwrite"); const p = l.objectStore(_s).delete(t); p.onsuccess = () => e(c.result.modelArtifactsInfo), p.onerror = f => s(c.error) }; u.onsuccess = d, u.onerror = h => (d(), r.close(), s(c.error)) } }, c.onerror = u => (r.close(), s(c.error)), i.oncomplete = () => { l == null ? r.close() : l.oncomplete = () => r.close() } }, o.onerror = r => s(o.error) }) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qn = "/", zo = "tensorflowjs_models", pm = "info", DC = "model_topology", WC = "weight_specs", MC = "weight_data", FC = "model_metadata"; function fm(n) { return { info: [zo, n, pm].join(qn), topology: [zo, n, DC].join(qn), weightSpecs: [zo, n, WC].join(qn), weightData: [zo, n, MC].join(qn), modelMetadata: [zo, n, FC].join(qn) } } function mm(n) { for (const t of Object.values(n)) window.localStorage.removeItem(t) } function VC(n) { const t = n.split(qn); if (t.length < 3) throw new Error(`Invalid key format: ${n}`); return t.slice(1, t.length - 1).join(qn) } function zC(n) { return n.startsWith(Ys.URL_SCHEME) ? n.slice(Ys.URL_SCHEME.length) : n } class Ys { constructor(t) { if (!A().getBool("IS_BROWSER") || typeof window > "u" || typeof window.localStorage > "u") throw new Error("The current environment does not support local storage."); if (this.LS = window.localStorage, t == null || !t) throw new Error("For local storage, modelPath must not be null, undefined or empty."); this.modelPath = t, this.keys = fm(this.modelPath) } async save(t) { if (t.modelTopology instanceof ArrayBuffer) throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet."); { const e = JSON.stringify(t.modelTopology), s = JSON.stringify(t.weightSpecs), o = um(t); try { this.LS.setItem(this.keys.info, JSON.stringify(o)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, s), this.LS.setItem(this.keys.weightData, TC(t.weightData)); const r = { format: t.format, generatedBy: t.generatedBy, convertedBy: t.convertedBy, signature: t.signature != null ? t.signature : void 0, userDefinedMetadata: t.userDefinedMetadata != null ? t.userDefinedMetadata : void 0, modelInitializer: t.modelInitializer != null ? t.modelInitializer : void 0, initializerSignature: t.initializerSignature != null ? t.initializerSignature : void 0, trainingConfig: t.trainingConfig != null ? t.trainingConfig : void 0 }; return this.LS.setItem(this.keys.modelMetadata, JSON.stringify(r)), { modelArtifactsInfo: o } } catch { throw mm(this.keys), new Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${o.modelTopologyBytes}, weightSpecsBytes=${o.weightSpecsBytes}, weightDataBytes=${o.weightDataBytes}.`) } } } async load() { const t = JSON.parse(this.LS.getItem(this.keys.info)); if (t == null) throw new Error(`In local storage, there is no model with name '${this.modelPath}'`); if (t.modelTopologyType !== "JSON") throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet."); const e = {}, s = JSON.parse(this.LS.getItem(this.keys.topology)); if (s == null) throw new Error(`In local storage, the topology of model '${this.modelPath}' is missing.`); e.modelTopology = s; const o = JSON.parse(this.LS.getItem(this.keys.weightSpecs)); if (o == null) throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`); e.weightSpecs = o; const r = this.LS.getItem(this.keys.modelMetadata); if (r != null) { const a = JSON.parse(r); e.format = a.format, e.generatedBy = a.generatedBy, e.convertedBy = a.convertedBy, a.signature != null && (e.signature = a.signature), a.userDefinedMetadata != null && (e.userDefinedMetadata = a.userDefinedMetadata), a.modelInitializer != null && (e.modelInitializer = a.modelInitializer), a.initializerSignature != null && (e.initializerSignature = a.initializerSignature), a.trainingConfig != null && (e.trainingConfig = a.trainingConfig) } const i = this.LS.getItem(this.keys.weightData); if (i == null) throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`); return e.weightData = NC(i), e } } Ys.URL_SCHEME = "localstorage://"; const gm = n => A().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(Ys.URL_SCHEME) ? XC(n.slice(Ys.URL_SCHEME.length)) : null; Re.registerSaveRouter(gm), Re.registerLoadRouter(gm); function XC(n) { return new Ys(n) } class AC { constructor() { v(A().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), v(typeof window > "u" || typeof window.localStorage < "u", () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage } async listModels() { const t = {}, e = zo + qn, s = qn + pm; for (let o = 0; o < this.LS.length; ++o) { const r = this.LS.key(o); if (r.startsWith(e) && r.endsWith(s)) { const i = VC(r); t[i] = JSON.parse(this.LS.getItem(r)) } } return t } async removeModel(t) { t = zC(t); const e = fm(t); if (this.LS.getItem(e.info) == null) throw new Error(`Cannot find model at path '${t}'`); const s = JSON.parse(this.LS.getItem(e.info)); return mm(e), s } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const bm = "://"; class zn { constructor() { this.managers = {} } static getInstance() { return zn.instance == null && (zn.instance = new zn), zn.instance } static registerManager(t, e) { v(t != null, () => "scheme must not be undefined or null."), t.endsWith(bm) && (t = t.slice(0, t.indexOf(bm))), v(t.length > 0, () => "scheme must not be an empty string."); const s = zn.getInstance(); v(s.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), s.managers[t] = e } static getManager(t) { const e = zn.getInstance().managers[t]; if (e == null) throw new Error(`Cannot find model manager for scheme '${t}'`); return e } static getSchemes() { return Object.keys(zn.getInstance().managers) } }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class OC { constructor() { this.messageName = "setTimeoutCustom", this.functionRefs = [], this.handledMessageCount = 0, this.hasEventListener = !1 } fetch(t, e) { return fetch(t, e) } now() { return performance.now() } encode(t, e) { if (e !== "utf-8" && e !== "utf8") throw new Error(`Browser's encoder only supports utf-8, but got ${e}`); return this.textEncoder == null && (this.textEncoder = new TextEncoder), this.textEncoder.encode(t) } decode(t, e) { return new TextDecoder(e).decode(t) } setTimeoutCustom(t, e) { if (typeof window > "u" || !A().getBool("USE_SETTIMEOUTCUSTOM")) { setTimeout(t, e); return } this.functionRefs.push(t), setTimeout(() => { window.postMessage({ name: this.messageName, index: this.functionRefs.length - 1 }, "*") }, e), this.hasEventListener || (this.hasEventListener = !0, window.addEventListener("message", s => { if (s.source === window && s.data.name === this.messageName) { s.stopPropagation(); const o = this.functionRefs[s.data.index]; o(), this.handledMessageCount++, this.handledMessageCount === this.functionRefs.length && (this.functionRefs = [], this.handledMessageCount = 0) } }, !0)) } isTypedArray(t) { return t instanceof Float32Array || t instanceof Int32Array || t instanceof Uint8Array || t instanceof Uint8ClampedArray } } if (A().get("IS_BROWSER")) { A().setPlatform("browser", new OC); try { zn.registerManager(Ys.URL_SCHEME, new AC) } catch { } try { zn.registerManager(Us.URL_SCHEME, new EC) } catch { } }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const PC = { importFetch: () => require("node-fetch") }; let ed; class KC { constructor() { this.util = require("util"), this.textEncoder = new this.util.TextEncoder } fetch(t, e) { return A().global.fetch != null ? A().global.fetch(t, e) : (ed == null && (ed = PC.importFetch()), ed(t, e)) } now() { const t = process.hrtime(); return t[0] * 1e3 + t[1] / 1e6 } encode(t, e) { if (e !== "utf-8" && e !== "utf8") throw new Error(`Node built-in encoder only supports utf-8, but got ${e}`); return this.textEncoder.encode(t) } decode(t, e) { return t.length === 0 ? "" : new this.util.TextDecoder(e).decode(t) } isTypedArray(t) { return this.util.types.isFloat32Array(t) || this.util.types.isInt32Array(t) || this.util.types.isUint8Array(t) || this.util.types.isUint8ClampedArray(t) } } A().get("IS_NODE") && !A().get("IS_BROWSER") && A().setPlatform("node", new KC);/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ct(n, t = "float32", e) { return t = t || "float32", jn(n), new ke(n, t, e) }/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ZC(n, t) { const e = N(n, "x", "cast"); if (!XI(t)) throw new Error(`Failed to cast to unknown dtype ${t}`); if (t === "string" && e.dtype !== "string" || t !== "string" && e.dtype === "string") throw new Error("Only strings can be casted to strings"); const s = { x: e }, o = { dtype: t }; return L.runKernel(Tr, s, o) } const ot = W({ cast_: ZC });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function BC(n) { const e = { x: N(n, "x", "clone", "string_or_numeric") }; return L.runKernel(Xr, e) } const Qs = W({ clone_: BC });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function HC(n, t = !1) { console.log(n.toString(t)) }/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */em(), bC({ buffer: Ct, cast: ot, clone: Qs, print: HC });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ft() { return L } function vc() { return L.memory() } function M(n, t) { return L.tidy(n, t) } function wt(n) { jf(n).forEach(e => e.dispose()) } function tn(n) { return L.keep(n) } function xm(n, t, e = 1) { return L.registerBackend(n, t, e) } function bs() { return L.backend }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _C(n, t) { let e = N(n, "a", "add"), s = N(t, "b", "add");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(Lo, o) } const Q = W({ add_: _C });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function UC(n, t) { let e = N(n, "a", "floorDiv"), s = N(t, "b", "floorDiv");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(Vr, o) } const ym = W({ floorDiv_: UC });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function YC(n, t) { let e = N(n, "a", "div"), s = N(t, "b", "div"); if ([e, s] = qt(e, s), e.dtype === "int32" && s.dtype === "int32") return ym(e, s); const o = { a: e, b: s }, r = {}; return L.runKernel(Lr, o, r) } const dt = W({ div_: YC });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QC(n, t) { let e = N(n, "a", "mul"), s = N(t, "b", "mul");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(Ur, o) } const E = W({ mul_: QC });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JC(n) { const t = N(n, "x", "abs"); if (t.dtype === "complex64") { const e = { x: t }; return L.runKernel(wa, e) } else { const e = { x: t }; return L.runKernel(ma, e) } } const $e = W({ abs_: JC });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jC(n) { const e = { x: N(n, "x", "acos") }; return L.runKernel(yr, e) } const qC = W({ acos_: jC });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tw(n) { const e = { x: N(n, "x", "acosh") }; return L.runKernel(Ir, e) } const ew = W({ acosh_: tw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nw(n, t = null, e = !1) { const o = { x: N(n, "x", "all", "bool") }, r = { axis: t, keepDims: e }; return L.runKernel(ql, o, r) } const Im = W({ all_: nw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sw(n, t = null, e = !1) { const o = { x: N(n, "x", "any", "bool") }, r = { axis: t, keepDims: e }; return L.runKernel(tu, o, r) } const nd = W({ any_: sw });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ow(n, t = 0) { const s = { x: N(n, "x", "argMax") }, o = { axis: t }; return L.runKernel(ga, s, o) } const yi = W({ argMax_: ow });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rw(n, t = 0) { const s = { x: N(n, "x", "argMin") }, o = { axis: t }; return L.runKernel(ba, s, o) } const iw = W({ argMin_: rw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aw(n) { const e = { x: N(n, "x", "asin") }; return L.runKernel(Cr, e) } const cw = W({ asin_: aw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lw(n) { const e = { x: N(n, "x", "asinh") }; return L.runKernel(wr, e) } const uw = W({ asinh_: lw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dw(n) { const e = { x: N(n, "x", "atan") }; return L.runKernel(vr, e) } const hw = W({ atan_: dw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pw(n, t) { let e = N(n, "a", "atan2"), s = N(t, "b", "atan2");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(kr, o) } const fw = W({ atan2_: pw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mw(n) { const e = { x: N(n, "x", "atanh") }; return L.runKernel(Sr, e) } const gw = W({ atanh_: mw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ii(n, t, e, s, o = "NHWC", r) { const i = n[3], a = [...t, i], c = es(o); return ye(n, a, e, r, s, null, null, c) } function hn(n, t, e, s, o, r, i = "channelsLast") { const [a, c] = Ci(t); let l; if (i === "channelsLast") l = [a, c, n[3], n[3]]; else if (i === "channelsFirst") l = [a, c, n[1], n[1]]; else throw new Error(`Unknown dataFormat ${i}`); return ye(n, l, e, s, o, r, !1, i) } function ts(n, t, e, s, o, r, i = "NDHWC") { const [a, c, l] = od(t); let u, d; if (i === "NDHWC") d = "channelsLast", u = [a, c, l, n[4], n[4]]; else if (i === "NCDHW") d = "channelsFirst", u = [a, c, l, n[1], n[1]]; else throw new Error(`Unknown dataFormat ${i}`); return xs(n, u, e, s, o, !1, d, r) } function ye(n, t, e, s, o, r, i = !1, a = "channelsLast") { let [c, l, u, d] = [-1, -1, -1, -1]; if (a === "channelsLast") [c, l, u, d] = n; else if (a === "channelsFirst") [c, d, l, u] = n; else throw new Error(`Unknown dataFormat ${a}`); const [h, p, , f] = t, [m, g] = Ci(e), [b, x] = Ci(s), I = Xo(h, b), y = Xo(p, x), { padInfo: C, outHeight: w, outWidth: k } = yw(o, l, u, m, g, I, y, r, a), S = i ? f * d : f; let T; return a === "channelsFirst" ? T = [c, S, w, k] : a === "channelsLast" && (T = [c, w, k, S]), { batchSize: c, dataFormat: a, inHeight: l, inWidth: u, inChannels: d, outHeight: w, outWidth: k, outChannels: S, padInfo: C, strideHeight: m, strideWidth: g, filterHeight: h, filterWidth: p, effectiveFilterHeight: I, effectiveFilterWidth: y, dilationHeight: b, dilationWidth: x, inShape: n, outShape: T, filterShape: t } } function xs(n, t, e, s, o, r = !1, i = "channelsLast", a) { let [c, l, u, d, h] = [-1, -1, -1, -1, -1]; if (i === "channelsLast") [c, l, u, d, h] = n; else if (i === "channelsFirst") [c, h, l, u, d] = n; else throw new Error(`Unknown dataFormat ${i}`); const [p, f, m, , g] = t, [b, x, I] = od(e), [y, C, w] = od(s), k = Xo(p, y), S = Xo(f, C), T = Xo(m, w), { padInfo: R, outDepth: G, outHeight: F, outWidth: V } = Iw(o, l, u, d, b, x, I, k, S, T, a), z = r ? g * h : g; let X; return i === "channelsFirst" ? X = [c, z, G, F, V] : i === "channelsLast" && (X = [c, G, F, V, z]), { batchSize: c, dataFormat: i, inDepth: l, inHeight: u, inWidth: d, inChannels: h, outDepth: G, outHeight: F, outWidth: V, outChannels: z, padInfo: R, strideDepth: b, strideHeight: x, strideWidth: I, filterDepth: p, filterHeight: f, filterWidth: m, effectiveFilterDepth: k, effectiveFilterHeight: S, effectiveFilterWidth: T, dilationDepth: y, dilationHeight: C, dilationWidth: w, inShape: n, outShape: X, filterShape: t } } function bw(n, t, e, s, o) { s == null && (s = sd(n, t, e)); const r = n[0], i = n[1], a = wi((r - t + 2 * s) / e + 1, o), c = wi((i - t + 2 * s) / e + 1, o); return [a, c] } function xw(n, t, e, s, o, r) { o == null && (o = sd(n, t[0], s[0])); const i = [0, 0, 0, e]; for (let a = 0; a < 3; a++)n[a] + 2 * o >= t[a] && (i[a] = wi((n[a] - t[a] + 2 * o) / s[a] + 1, r)); return i } function sd(n, t, e, s = 1) { const o = Xo(t, s); return Math.floor((n[0] * (e - 1) - e + o) / 2) } function Ci(n) { return typeof n == "number" ? [n, n, n] : n.length === 2 ? [n[0], n[1], 1] : n } function od(n) { return typeof n == "number" ? [n, n, n] : n } function Xo(n, t) { return t <= 1 ? n : n + (n - 1) * (t - 1) } function yw(n, t, e, s, o, r, i, a, c) { let l, u, d; if (typeof n == "number") { l = { top: n, bottom: n, left: n, right: n, type: n === 0 ? "VALID" : "NUMBER" }; const p = bw([t, e], r, s, n, a); u = p[0], d = p[1] } else if (n === "same") { u = Math.ceil(t / s), d = Math.ceil(e / o); const h = Math.max(0, (u - 1) * s + r - t), p = Math.max(0, (d - 1) * o + i - e), f = Math.floor(h / 2), m = h - f, g = Math.floor(p / 2), b = p - g; l = { top: f, bottom: m, left: g, right: b, type: "SAME" } } else if (n === "valid") l = { top: 0, bottom: 0, left: 0, right: 0, type: "VALID" }, u = Math.ceil((t - r + 1) / s), d = Math.ceil((e - i + 1) / o); else if (typeof n == "object") { const h = c === "channelsLast" ? n[1][0] : n[2][0], p = c === "channelsLast" ? n[1][1] : n[2][1], f = c === "channelsLast" ? n[2][0] : n[3][0], m = c === "channelsLast" ? n[2][1] : n[3][1]; l = { top: h, bottom: p, left: f, right: m, type: h === 0 && p === 0 && f === 0 && m === 0 ? "VALID" : "EXPLICIT" }, u = wi((t - r + h + p) / s + 1, a), d = wi((e - i + f + m) / o + 1, a) } else throw Error(`Unknown padding parameter: ${n}`); return { padInfo: l, outHeight: u, outWidth: d } } function Iw(n, t, e, s, o, r, i, a, c, l, u) { let d, h, p, f; if (n === "valid" && (n = 0), typeof n == "number") { d = { top: n, bottom: n, left: n, right: n, front: n, back: n, type: n === 0 ? "VALID" : "NUMBER" }; const g = xw([t, e, s, 1], [a, c, l], 1, [o, r, i], n, u); h = g[0], p = g[1], f = g[2] } else if (n === "same") { h = Math.ceil(t / o), p = Math.ceil(e / r), f = Math.ceil(s / i); const m = (h - 1) * o + a - t, g = (p - 1) * r + c - e, b = (f - 1) * i + l - s, x = Math.floor(m / 2), I = m - x, y = Math.floor(g / 2), C = g - y, w = Math.floor(b / 2), k = b - w; d = { top: y, bottom: C, left: w, right: k, front: x, back: I, type: "SAME" } } else throw Error(`Unknown padding parameter: ${n}`); return { padInfo: d, outDepth: h, outHeight: p, outWidth: f } } function wi(n, t) { if (!t) return Math.trunc(n); switch (t) { case "round": return Math.round(n); case "ceil": return Math.ceil(n); case "floor": return Math.floor(n); default: throw new Error(`Unknown roundingMode ${t}`) } } function Js(n) { const [t, e, s] = Ci(n); return t === 1 && e === 1 && s === 1 } function Te(n, t) { return Js(n) || Js(t) } function js(n) { return Ci(n).every(t => t > 0) } function es(n) { if (n === "NHWC") return "channelsLast"; if (n === "NCHW") return "channelsFirst"; throw new Error(`Unknown dataFormat ${n}`) } function Fe(n, t, e) { if (e != null) { if (typeof t == "string") throw Error(`Error in ${n}: pad must be an integer when using dimRoundingMode ${e} but got pad ${t}.`); if (typeof t == "number") v(Ro(t), () => `Error in ${n}: pad must be an integer when using dimRoundingMode ${e} but got pad ${t}.`); else if (typeof t == "object") t.forEach(s => { s.forEach(o => { v(Ro(o), () => `Error in ${n}: pad must be an integer when using dimRoundingMode ${e} but got pad ${o}.`) }) }); else throw Error(`Error in ${n}: Unknown padding parameter: ${t}`) } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Cw(n, t) { const s = { x: N(n, "x", "reshape", "string_or_numeric") }, o = { shape: t }; return L.runKernel(nc, s, o) } const D = W({ reshape_: Cw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ww(n, t, e, s, o) { const r = N(n, "x", "avgPool", "float32"), i = 1; v(Te(e, i), () => `Error in avgPool: Either strides or dilations must be 1. Got strides ${e} and dilations '${i}'`); let a = r, c = !1; r.rank === 3 && (c = !0, a = D(r, [1, r.shape[0], r.shape[1], r.shape[2]])), v(a.rank === 4, () => `Error in avgPool: x must be rank 4 but got rank ${a.rank}.`), Fe("avgPool", s, o); const l = { x: a }, u = { filterSize: t, strides: e, pad: s, dimRoundingMode: o }; let d = L.runKernel(xa, l, u); return d = ot(d, r.dtype), c ? D(d, [d.shape[1], d.shape[2], d.shape[3]]) : d } const rd = W({ avgPool_: ww });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function vw(n, t, e, s, o, r = "NDHWC") { const i = N(n, "x", "avgPool3d", "float32"); let a = i, c = !1; i.rank === 4 && (c = !0, a = D(i, [1, i.shape[0], i.shape[1], i.shape[2], i.shape[3]])), v(a.rank === 5, () => `Error in avgPool3d: x must be rank 5 but got rank ${a.rank}.`), v(r === "NDHWC", () => `Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of ${r}`), v(typeof e == "number" && e > 0 || Array.isArray(e) && e[0] > 0 && e[1] > 0 && e[2] > 0, () => `Error in avgPool3d: Stride must be > 0, but got '${e}'`), Fe("avgPool3d", s, o); const l = { x: a }, u = { filterSize: t, strides: e, pad: s, dimRoundingMode: o, dataFormat: r }; let d = L.runKernel(ya, l, u); return d = ot(d, a.dtype), c ? D(d, [d.shape[1], d.shape[2], d.shape[3], d.shape[4]]) : d } const Sw = W({ avgPool3d_: vw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kw(n, t = 0) {
        v(n.length >= 1, () => "Pass at least one tensor to concat"); const e = im(n, "tensors", "concat", "string_or_numeric"); if (e[0].dtype === "complex64" && e.forEach(r => {
            if (r.dtype !== "complex64") throw new Error(`Cannot concatenate complex64 tensors with a tensor
          with dtype ${r.dtype}. `)
        }), e.length === 1) return Qs(e[0]); const s = e, o = { axis: t }; return L.runKernel(va, s, o)
    } const Ve = W({ concat_: kw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Tw(n, t, e = !1, s = !1) { let o = N(n, "a", "matMul"), r = N(t, "b", "matMul");[o, r] = qt(o, r); const i = { a: o, b: r }, a = { transposeA: e, transposeB: s }; return L.runKernel(Ia, i, a) } const $t = W({ matMul_: Tw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Nw(n) { const e = { x: N(n, "x", "sigmoid", "float32") }; return L.runKernel(ri, e) } const Ao = W({ sigmoid_: Nw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Rw(n, t, e) { const s = N(n, "x", "slice", "string_or_numeric"); if (s.rank === 0) throw new Error("Slicing scalar is not possible"); const o = { x: s }, r = { begin: t, size: e }; return L.runKernel(ac, o, r) } const Vt = W({ slice_: Rw });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $w(n) { const e = { x: N(n, "x", "tanh", "float32") }; return L.runKernel(di, e) } const id = W({ tanh_: $w });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gw(n, t, e) { const s = N(n, "x", "batchToSpaceND"), o = t.reduce((a, c) => a * c); v(s.rank >= 1 + t.length, () => `input rank is ${s.rank} but should be > than blockShape.length ${t.length}`), v(e.length === t.length, () => `crops.length is ${e.length} but should be equal to blockShape.length  ${t.length}`), v(s.shape[0] % o === 0, () => `input tensor batch is ${s.shape[0]} but is not divisible by the product of the elements of blockShape ${t.join(" * ")} === ${o}`); const r = { x: s }, i = { blockShape: t, crops: e }; return L.runKernel(Ca, r, i) } const ad = W({ batchToSpaceND_: Gw }); function Lw(n) { let t; return n.rank === 0 || n.rank === 1 ? t = D(n, [1, 1, 1, n.size]) : n.rank === 2 ? t = D(n, [1, 1, n.shape[0], n.shape[1]]) : n.rank === 3 ? t = D(n, [1, n.shape[0], n.shape[1], n.shape[2]]) : t = n, t }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ew(n, t, e, s, o, r) { r == null && (r = .001); const i = N(n, "x", "batchNorm"), a = N(t, "mean", "batchNorm"), c = N(e, "variance", "batchNorm"); let l; o != null && (l = N(o, "scale", "batchNorm")); let u; s != null && (u = N(s, "offset", "batchNorm")), v(a.rank === c.rank, () => "Batch normalization gradient requires mean and variance to have equal ranks."), v(u == null || a.rank === u.rank, () => "Batch normalization gradient requires mean and offset to have equal ranks."), v(l == null || a.rank === l.rank, () => "Batch normalization gradient requires mean and scale to have equal ranks."); const h = { x: Lw(i), scale: l, offset: u, mean: a, variance: c }, p = { varianceEpsilon: r }, f = L.runKernel(Ea, h, p); return D(f, i.shape) } const Sc = W({ batchNorm_: Ew }); function Dw(n, t, e, s, o, r) { const i = N(n, "x", "batchNorm"), a = N(t, "mean", "batchNorm"), c = N(e, "variance", "batchNorm"); let l; o != null && (l = N(o, "scale", "batchNorm")); let u; return s != null && (u = N(s, "offset", "batchNorm")), v(i.rank === 2, () => `Error in batchNorm2D: x must be rank 2 but got rank ${i.rank}.`), v(a.rank === 2 || a.rank === 1, () => `Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank ${a.rank}.`), v(c.rank === 2 || c.rank === 1, () => `Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank ${c.rank}.`), l != null && v(l.rank === 2 || l.rank === 1, () => `Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank ${l.rank}.`), u != null && v(u.rank === 2 || u.rank === 1, () => `Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank ${u.rank}.`), Sc(i, a, c, u, l, r) } const Ww = W({ batchNorm2d_: Dw }); function Mw(n, t, e, s, o, r) { const i = N(n, "x", "batchNorm"), a = N(t, "mean", "batchNorm"), c = N(e, "variance", "batchNorm"); let l; o != null && (l = N(o, "scale", "batchNorm")); let u; return s != null && (u = N(s, "offset", "batchNorm")), v(i.rank === 3, () => `Error in batchNorm3D: x must be rank 3 but got rank ${i.rank}.`), v(a.rank === 3 || a.rank === 1, () => `Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank ${a.rank}.`), v(c.rank === 3 || c.rank === 1, () => `Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank ${c.rank}.`), l != null && v(l.rank === 3 || l.rank === 1, () => `Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank ${l.rank}.`), u != null && v(u.rank === 3 || u.rank === 1, () => `Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank ${u.rank}.`), Sc(i, a, c, u, l, r) } const Fw = W({ batchNorm3d_: Mw }); function Vw(n, t, e, s, o, r) { const i = N(n, "x", "batchNorm"), a = N(t, "mean", "batchNorm"), c = N(e, "variance", "batchNorm"); let l; o != null && (l = N(o, "scale", "batchNorm")); let u; return s != null && (u = N(s, "offset", "batchNorm")), v(i.rank === 4, () => `Error in batchNorm4D: x must be rank 4 but got rank ${i.rank}.`), v(a.rank === 4 || a.rank === 1, () => `Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank ${a.rank}.`), v(c.rank === 4 || c.rank === 1, () => `Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank ${c.rank}.`), l != null && v(l.rank === 4 || l.rank === 1, () => `Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank ${l.rank}.`), u != null && v(u.rank === 4 || u.rank === 1, () => `Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank ${u.rank}.`), Sc(i, a, c, u, l, r) } const zw = W({ batchNorm4d_: Vw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Xw(n, t, e) { const s = N(n, "x", "bincount"), o = N(t, "weights", "bincount"); v(s.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${s.dtype}`), v(e >= 0, () => `size must be non-negative, but got ${e}.`), v(o.size === s.size || o.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${s.shape}, weights shape: ${o.shape}.`); const r = { x: s, weights: o }, i = { size: e }; return L.runKernel(su, r, i) } const Aw = W({ bincount_: Xw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ow(n, t) { let e = N(n, "broadcastTo", "x"); const s = e.shape; if (jn(t), t.length < e.rank) throw new Error(`broadcastTo(): shape.length=${t.length} < input.rank=${e.rank}.`); if (t.length > e.rank) { const l = e.shape.slice(); for (; l.length < t.length;)l.unshift(1); e = D(e, l) } const o = e.shape, r = Array.from(t); for (let l = t.length - 1; l >= 0; l--)if (o[l] === t[l]) r[l] = 1; else if (e.shape[l] !== 1) throw new Error(`broadcastTo(): [${s}] cannot be broadcast to [${t}].`); if (r.map((l, u) => l > 1 ? u : -1).filter(l => l >= 0).length === 0) return Qs(e); const a = { x: e }, c = { reps: r }; return L.runKernel(hi, a, c) } const vi = W({ broadcastTo_: Ow });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Pw(n) { const e = { x: N(n, "x", "ceil", "float32") }; return L.runKernel(Nr, e) } const Kw = W({ ceil_: Pw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kc(n, t, e) { jn(n); const s = { shape: n, value: t, dtype: e }; return L.runKernel(xu, {}, s) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Zw(n, t, e) { const s = N(n, "x", "clipByValue"); if (v(t <= e, () => `Error in clip: min (${t}) must be less than or equal to max (${e}).`), t === e) return kc(s.shape, t, s.dtype); const o = { x: s }, r = { clipValueMin: t, clipValueMax: e }; return L.runKernel(Rr, o, r) } const en = W({ clipByValue_: Zw }); function Bw(n) { return Ve(n, 0) } const Hw = W({ concat1d_: Bw }); function _w(n, t) { return Ve(n, t) } const Uw = W({ concat2d_: _w }); function Yw(n, t) { return Ve(n, t) } const Qw = W({ concat3d_: Yw }); function Jw(n, t) { return Ve(n, t) } const jw = W({ concat4d_: Jw });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qw(n, t, e, s, o = "NHWC", r = [1, 1], i) { const a = N(n, "x", "conv2d", "float32"), c = N(t, "filter", "conv2d", "float32"); let l = a, u = !1; a.rank === 3 && (u = !0, l = D(a, [1, a.shape[0], a.shape[1], a.shape[2]])), v(l.rank === 4, () => `Error in conv2d: input must be rank 4, but got rank ${l.rank}.`), v(c.rank === 4, () => `Error in conv2d: filter must be rank 4, but got rank ${c.rank}.`), Fe("conv2d", s, i); const d = o === "NHWC" ? l.shape[3] : l.shape[1]; v(d === c.shape[2], () => `Error in conv2d: depth of input (${d}) must match input depth for filter ${c.shape[2]}.`), v(Te(e, r), () => `Error in conv2D: Either strides or dilations must be 1. Got strides ${e} and dilations '${r}'`), v(js(r), () => "Error in conv2D: Dilated rates should be larger than 0."), v(js(e), () => "Error in conv2D: Strides should be larger than 0."); const h = { x: l, filter: c }, p = { strides: e, pad: s, dataFormat: o, dilations: r, dimRoundingMode: i }, f = L.runKernel(Sa, h, p); return u ? D(f, [f.shape[1], f.shape[2], f.shape[3]]) : f } const qs = W({ conv2d_: qw }); function t2(n, t, e, s, o = "NWC", r = 1, i) { const a = N(n, "x", "conv1d"), c = N(t, "filter", "conv1d"); let l = a, u = !1; a.rank === 2 && (u = !0, l = D(a, [1, a.shape[0], a.shape[1]])), v(l.rank === 3, () => `Error in conv1d: input must be rank 3, but got rank ${l.rank}.`), v(c.rank === 3, () => `Error in conv1d: filter must be rank 3, but got rank ${c.rank}.`), Fe("conv1d", s, i), v(l.shape[2] === c.shape[1], () => `Error in conv1d: depth of input (${l.shape[2]}) must match input depth for filter ${c.shape[1]}.`), v(Te(e, r), () => `Error in conv1D: Either stride or dilation must be 1. Got stride ${e} and dilation '${r}'`), v(js(r), () => "Error in conv1D: Dilated rates should be larger than 0."), v(js(e), () => "Error in conv1D: Stride should be larger than 0."), v(o === "NWC", () => `Error in conv1d: got dataFormat of ${o} but only NWC is currently supported.`); const d = D(c, [1, c.shape[0], c.shape[1], c.shape[2]]), h = D(l, [l.shape[0], 1, l.shape[1], l.shape[2]]), g = qs(h, d, [1, e], s, "NHWC", [1, r], i); return u ? D(g, [g.shape[2], g.shape[3]]) : D(g, [g.shape[0], g.shape[2], g.shape[3]]) } const Cm = W({ conv1d_: t2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function e2(n, t, e, s, o, r = "NHWC", i) { v(n.length === t.rank, () => `Length of inShape (${n.length}) and rank of dy (${t.rank}) must match`); let a = n, c = t, l = !1; t.rank === 3 && (l = !0, c = D(t, [1, t.shape[0], t.shape[1], t.shape[2]]), a = [1, n[0], n[1], n[2]]), v(a.length === 4, () => `Error in conv2dDerInput: inShape must be length 4, but got length ${a.length}.`), v(c.rank === 4, () => `Error in conv2dDerInput: dy must be rank 4, but got rank ${c.rank}`), v(e.rank === 4, () => `Error in conv2dDerInput: filter must be rank 4, but got rank ${e.rank}`); const u = r === "NHWC" ? a[3] : a[1], d = r === "NHWC" ? c.shape[3] : c.shape[1]; v(u === e.shape[2], () => `Error in conv2dDerInput: depth of input (${u}) must match input depth for filter ${e.shape[2]}.`), v(d === e.shape[3], () => `Error in conv2dDerInput: depth of output (${d}) must match output depth for filter ${e.shape[3]}.`), Fe("conv2dDerInput", o, i); const h = { dy: c, filter: e }, p = { strides: s, pad: o, dataFormat: r, dimRoundingMode: i, inputShape: a }, f = L.runKernel(ka, h, p); return l ? D(f, [f.shape[1], f.shape[2], f.shape[3]]) : f } const cd = W({ conv2DBackpropInput_: e2 }); function n2(n, t, e, s, o, r) { const i = N(n, "x", "conv2dTranspose"), a = N(t, "filter", "conv2dTranspose"); return cd(e, i, a, s, o, "NHWC", r) } const wm = W({ conv2dTranspose_: n2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function s2(n, t, e, s, o = "NDHWC", r = [1, 1, 1]) { const i = N(n, "x", "conv3d"), a = N(t, "filter", "conv3d"); let c = i, l = !1; i.rank === 4 && (l = !0, c = D(i, [1, i.shape[0], i.shape[1], i.shape[2], i.shape[3]])), v(c.rank === 5, () => `Error in conv3d: input must be rank 5, but got rank ${c.rank}.`), v(a.rank === 5, () => `Error in conv3d: filter must be rank 5, but got rank ${a.rank}.`), v(c.shape[4] === a.shape[3], () => `Error in conv3d: depth of input (${c.shape[4]}) must match input depth for filter ${a.shape[3]}.`), v(Te(e, r), () => `Error in conv3D: Either strides or dilations must be 1. Got strides ${e} and dilations '${r}'`), v(o === "NDHWC", () => `Error in conv3d: got dataFormat of ${o} but only NDHWC is currently supported.`), v(js(r), () => "Error in conv3D: Dilated rates should be larger than 0."), v(js(e), () => "Error in conv3D: Strides should be larger than 0."); const u = { x: c, filter: a }, d = { strides: e, pad: s, dataFormat: o, dilations: r }, h = L.runKernel(Ta, u, d); return l ? D(h, [h.shape[1], h.shape[2], h.shape[3], h.shape[4]]) : h } const o2 = W({ conv3d_: s2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function r2(n, t, e, s, o) { v(n.length === t.rank, () => `Length of inShape (${n.length}) and rank of dy (${t.rank}) must match`); let r = n, i = t, a = !1; t.rank === 4 && (a = !0, i = D(t, [1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]]), r = [1, n[0], n[1], n[2], n[3]]); const c = r[4], l = i.shape[4]; v(r.length === 5, () => `Error in conv3dDerInput: inShape must be length 5, but got length ${r.length}.`), v(i.rank === 5, () => `Error in conv3dDerInput: dy must be rank 5, but got rank ${i.rank}`), v(e.rank === 5, () => `Error in conv3dDerInput: filter must be rank 5, but got rank ${e.rank}`), v(c === e.shape[3], () => `Error in conv3dDerInput: depth of input (${c}) must match input depth for filter ${e.shape[3]}.`), v(l === e.shape[4], () => `Error in conv3dDerInput: depth of output (${l}) must match output depth for filter ${e.shape[4]}.`); const u = { dy: i, filter: e }, d = { pad: o, strides: s, inputShape: r }, h = L.runKernel(au, u, d); return a ? D(h, [h.shape[1], h.shape[2], h.shape[3], h.shape[4]]) : h } const vm = W({ conv3DBackpropInput_: r2 }); function i2(n, t, e, s, o) { const r = N(n, "x", "conv3dTranspose"), i = N(t, "filter", "conv3dTranspose"); return vm(e, r, i, s, o) } const a2 = W({ conv3dTranspose_: i2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function c2(n) { const e = { x: N(n, "x", "cos", "float32") }; return L.runKernel($r, e) } const ld = W({ cos_: c2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function l2(n) { const e = { x: N(n, "x", "cosh", "float32") }; return L.runKernel(Gr, e) } const Sm = W({ cosh_: l2 });/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function u2(n, t = 0, e = !1, s = !1) { const r = { x: N(n, "x", "cumprod") }, i = { axis: t, exclusive: e, reverse: s }; return L.runKernel(cu, r, i) } const ud = W({ cumprod_: u2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function d2(n, t = 0, e = !1, s = !1) { const r = { x: N(n, "x", "cumsum") }, i = { axis: t, exclusive: e, reverse: s }; return L.runKernel(Na, r, i) } const km = W({ cumsum_: d2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function h2(n, t, e, s = !1) { const o = N(n, "x", "denseBincount"), r = N(t, "weights", "denseBincount"); v(o.dtype === "int32", () => `Error in denseBincount: input dtype must be int32, but got ${o.dtype}`), v(o.rank <= 2, () => `Error in denseBincount: input must be at most rank 2, but got rank ${o.rank}.`), v(e >= 0, () => `size must be non-negative, but got ${e}.`), v(r.size === o.size || r.size === 0, () => `Error in denseBincount: weights must have the same shape as x or 0-length, but got x shape: ${o.shape}, weights shape: ${r.shape}.`); const i = { x: o, weights: r }, a = { size: e, binaryOutput: s }; return L.runKernel(uu, i, a) } const Tm = W({ denseBincount_: h2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function p2(n, t, e = "NHWC") {
        const s = N(n, "x", "depthToSpace", "float32"), o = e === "NHWC" ? s.shape[1] : s.shape[2], r = e === "NHWC" ? s.shape[2] : s.shape[3], i = e === "NHWC" ? s.shape[3] : s.shape[1]; v(t > 1, () => `blockSize should be > 1 for depthToSpace, but was: ${t}`), v(o * t >= 0, () => `Negative dimension size caused by overflow when multiplying
    ${o} and ${t}  for depthToSpace with input shape
    ${s.shape}`), v(r * t >= 0, () => `Negative dimension size caused by overflow when multiplying
    ${r} and ${t} for depthToSpace with input shape
        ${s.shape}`), v(i % (t * t) === 0, () => `Dimension size must be evenly divisible by ${t * t} but is ${i} for depthToSpace with input shape ${s.shape}`); const a = { x: s }, c = { blockSize: t, dataFormat: e }; return L.runKernel(du, a, c)
    } const f2 = W({ depthToSpace_: p2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function m2(n, t, e, s, o = "NHWC", r = [1, 1], i) { const a = N(n, "x", "depthwiseConv2d", "float32"), c = N(t, "filter", "depthwiseConv2d", "float32"); let l = a, u = !1; a.rank === 3 && (u = !0, l = D(a, [1, a.shape[0], a.shape[1], a.shape[2]])), v(l.rank === 4, () => `Error in depthwiseConv2d: input must be rank 4, but got rank ${l.rank}.`), v(c.rank === 4, () => `Error in depthwiseConv2d: filter must be rank 4, but got rank ${c.rank}.`); const d = o === "NHWC" ? l.shape[3] : l.shape[1]; v(d === c.shape[2], () => `Error in depthwiseConv2d: number of input channels (${d}) must match the inChannels dimension in filter ${c.shape[2]}.`), Fe("depthwiseConv2d", s, i); const h = { x: l, filter: c }, p = { strides: e, pad: s, dataFormat: o, dilations: r, dimRoundingMode: i }, f = L.runKernel(Ra, h, p); return u ? D(f, [f.shape[1], f.shape[2], f.shape[3]]) : f } const dd = W({ depthwiseConv2d_: m2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function g2(n, t, e, s, o = [1, 1], r = "NHWC") { const i = N(n, "x", "dilation2d"), a = N(t, "filter", "dilation2d"); v(i.rank === 3 || i.rank === 4, () => `Error in dilation2d: input must be rank 3 or 4, but got rank ${i.rank}.`), v(a.rank === 3, () => `Error in dilation2d: filter must be rank 3, but got rank ${a.rank}.`), v(r === "NHWC", () => `Error in dilation2d: Only NHWC is currently supported, but got dataFormat of ${r}`); let c = i, l = !1; i.rank === 3 && (c = D(i, [1, i.shape[0], i.shape[1], i.shape[2]]), l = !0), v(c.shape[3] === a.shape[2], () => `Error in dilation2d:  input and filter must have the same depth: ${c.shape[3]} vs ${a.shape[2]}`); const u = { x: c, filter: a }, d = { strides: e, pad: s, dilations: o }, h = L.runKernel($a, u, d); return l ? D(h, [h.shape[1], h.shape[2], h.shape[3]]) : h } const b2 = W({ dilation2d_: g2 });/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Oo(n, t) { const e = n.length, s = []; for (let o = 0; o < e; o++) { const r = e - 1 - o, i = n[r] || 1; (t[t.length - 1 - o] || 1) > 1 && i === 1 && s.unshift(r) } return s } function ce(n, t) { const e = []; for (let s = 0; s < t.length; s++) { const o = n[n.length - s - 1], r = t.length - s - 1, i = t[r]; (o == null || o === 1 && i > 1) && e.unshift(r) } return e } function gt(n, t) { const e = [], s = Math.max(n.length, t.length); for (let o = 0; o < s; o++) { let r = n[n.length - o - 1]; r == null && (r = 1); let i = t[t.length - o - 1]; if (i == null && (i = 1), r === 1) e.unshift(i); else if (i === 1) e.unshift(r); else if (r !== i) { const a = `Operands could not be broadcast together with shapes ${n} and ${t}.`; throw Error(a) } else e.unshift(r) } return e }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function x2(n, t) { let e = N(n, "a", "equal", "string_or_numeric"), s = N(t, "b", "equal", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Ga, o) } const Xn = W({ equal_: x2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function y2(n, t, e) { const s = N(t, "a", "where"), o = N(e, "b", "where"), r = N(n, "condition", "where", "bool"), i = gt(gt(r.shape, s.shape), o.shape), a = vi(r, i), c = vi(s, i), l = vi(o, i), u = { condition: a, t: c, e: l }; return L.runKernel(ic, u) } const Be = W({ where_: y2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function I2(n) { const e = { x: N(n, "x", "zerosLike") }; return L.runKernel(fc, e) } const kt = W({ zerosLike_: I2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function C2(n, t) { let e = N(n, "a", "div"), s = N(t, "b", "div");[e, s] = qt(e, s); const o = dt(e, s), r = kt(o), i = Xn(s, r); return Be(i, r, o) } const w2 = W({ divNoNan_: C2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function v2(n, t) { const e = N(n, "t1", "dot"), s = N(t, "t2", "dot"); v((e.rank === 1 || e.rank === 2) && (s.rank === 1 || s.rank === 2), () => `Error in dot: inputs must all be rank 1 or 2, but got ranks ${e.rank} and ${s.rank}.`); const o = e.rank === 1 ? e.size : e.shape[1], r = s.rank === 1 ? s.size : s.shape[0]; if (v(o === r, () => `Error in dot: inner dimensions of inputs must match, but got ${o} and ${r}.`), e.rank === 1 && s.rank === 1) { const i = D(e, [1, -1]), a = D(s, [-1, 1]), c = $t(i, a); return D(c, []) } else if (e.rank === 1 && s.rank === 2) { const i = D(e, [1, -1]), a = D(s, [s.shape[0], s.shape[1]]), c = $t(i, a); return D(c, [c.size]) } else if (e.rank === 2 && s.rank === 1) { const i = D(s, [-1, 1]), a = $t(e, i); return D(a, [a.size]) } else { const i = D(s, [s.shape[0], s.shape[1]]); return $t(e, i) } } const S2 = W({ dot_: v2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function k2(n) { const e = { x: N(n, "x", "elu", "float32") }; return L.runKernel(Er, e) } const Tc = W({ elu_: k2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function T2(n) { let t = N(n, "x", "erf"); v(t.dtype === "int32" || t.dtype === "float32", () => "Input dtype must be `int32` or `float32`."), t.dtype === "int32" && (t = ot(t, "float32")); const e = { x: t }; return L.runKernel(Dr, e) } const N2 = W({ erf_: T2 });/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hd(n, t) { for (let e = 0; e < n.length; ++e)if (n[n.length - e - 1] !== t - 1 - e) return !1; return !0 } function Nm(n, t, e) { const s = n.length + t.length, o = []; let r = 0, i = 0; for (let a = 0; a < s; a++)e.indexOf(a) === -1 ? o.push(n[r++]) : o.push(t[i++]); return o } function fe(n, t) { const e = [], s = n.length; for (let r = 0; r < s; r++)t.indexOf(r) === -1 && e.push(n[r]); const o = t.map(r => n[r]); return [e, o] } function oe(n, t) { const e = t.map(s => 1); return Nm(n, e, t) } function Ie(n, t, e) { v(hd(t, e), () => `${n} supports only inner-most axes for now. Got axes ${t} and rank-${e} input.`) } function Yt(n, t) { if (hd(n, t)) return null; const e = []; for (let s = 0; s < t; ++s)n.indexOf(s) === -1 && e.push(s); return n.forEach(s => e.push(s)), e } function ys(n) { return n.map((t, e) => [e, t]).sort((t, e) => t[1] - e[1]).map(t => t[0]) } function te(n, t) { const e = []; for (let s = t - n; s < t; ++s)e.push(s); return e }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function R2(n, t = null, e = !1) { const o = { x: N(n, "x", "max") }, r = { reductionIndices: t, keepDims: e }; return L.runKernel(Pa, o, r) } const Tn = W({ max_: R2 });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $2(n, t = null, e = !1) { const o = { x: N(n, "x", "min") }, r = { axis: t, keepDims: e }; return L.runKernel(Ha, o, r) } const Nc = W({ min_: $2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function G2(n, t) { let e = N(n, "base", "pow"), s = N(t, "exp", "pow");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(Yr, o) } const Po = W({ pow_: G2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gt(n, t) { if ((Sn(n) && t !== "string" || Array.isArray(n)) && t !== "complex64") throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)"); if (t === "string" && Sn(n) && !(n instanceof Uint8Array)) throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`."); return xi(n, [], [], t) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function L2(n) { const e = { x: N(n, "x", "sqrt", "float32") }; return L.runKernel(ai, e) } const Ge = W({ sqrt_: L2 });/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function E2(n) { const t = N(n, "x", "square"), e = {}; return L.runKernel("Square", { x: t }, e) } const Zt = W({ square_: E2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function D2(n, t = null, e = !1) { let s = N(n, "x", "sum"); s.dtype === "bool" && (s = ot(s, "int32")); const o = { x: s }, r = { axis: t, keepDims: e }; return L.runKernel(cc, o, r) } const ut = W({ sum_: D2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function W2(n, t = "euclidean", e = null, s = !1) { n = N(n, "x", "norm"); const o = Rm(n, t, e); let r = o.shape; if (s) { const i = It(e, n.shape); r = oe(o.shape, i) } return D(o, r) } function Rm(n, t, e = null) { if (n.rank === 0) return $e(n); if (n.rank !== 1 && e === null) return Rm(D(n, [-1]), t, e); if (n.rank === 1 || typeof e == "number" || Array.isArray(e) && e.length === 1) { if (t === 1) return ut($e(n), e); if (t === 1 / 0) return Tn($e(n), e); if (t === -1 / 0) return Nc($e(n), e); if (t === "euclidean" || t === 2) return Ge(ut(Po($e(n), Gt(2, "int32")), e)); throw new Error(`Error in norm: invalid ord value: ${t}`) } if (Array.isArray(e) && e.length === 2) { if (t === 1) return Tn(ut($e(n), e[0]), e[1] - 1); if (t === 1 / 0) return Tn(ut($e(n), e[1]), e[0]); if (t === -1 / 0) return Nc(ut($e(n), e[1]), e[0]); if (t === "fro" || t === "euclidean") return Ge(ut(Zt(n), e)); throw new Error(`Error in norm: invalid ord value: ${t}`) } throw new Error(`Error in norm: invalid axis: ${e}`) } const Rc = W({ norm_: W2 });/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function M2(n, t = null, e = !1) { return Rc(n, "euclidean", t, e) } const F2 = W({ euclideanNorm_: M2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function V2(n) { const e = { x: N(n, "x", "exp") }; return L.runKernel(Wr, e) } const ns = W({ exp_: V2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function z2(n, t = 0) { const e = N(n, "x", "expandDims", "string_or_numeric"); v(t <= e.rank, () => "Axis must be <= rank of the tensor"); const s = { input: e }, o = { dim: t }; return L.runKernel(La, s, o) } const He = W({ expandDims_: z2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function X2(n) { const e = { x: N(n, "x", "expm1") }; return L.runKernel(Mr, e) } const A2 = W({ expm1_: X2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function O2(n, t) { const e = N(n, "x", "tile", "string_or_numeric"); v(e.rank === t.length, () => `Error in transpose: rank of input ${e.rank} must match length of reps ${t}.`); const s = { x: e }, o = { reps: t }; return L.runKernel(hi, s, o) } const Nn = W({ tile_: O2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function P2(n, t, e, s = "float32") { t == null && (t = n); const o = Ct([n, t], s), r = n <= t ? n : t; for (let a = 0; a < r; ++a)o.set(1, a, a); const i = D(o.toTensor(), [n, t]); if (e == null) return i; if (e.length === 1) return Nn(He(i, 0), [e[0], 1, 1]); if (e.length === 2) return Nn(He(He(i, 0), 0), [e[0], e[1], 1, 1]); if (e.length === 3) return Nn(He(He(He(i, 0), 0), 0), [e[0], e[1], e[2], 1, 1]); throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${e.length}D.`) } const $m = W({ eye_: P2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function K2(n) { const e = { x: N(n, "x", "floor", "float32") }; return L.runKernel(Fr, e) } const $c = W({ floor_: K2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Z2(n, t, e = 0, s = 0) { const o = N(n, "x", "gather"), r = N(t, "indices", "gather", "int32"), i = { x: o, indices: r }, a = { axis: e, batchDims: s }; return L.runKernel(Da, i, a) } const pd = W({ gather_: Z2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function B2(n, t) { let e = N(n, "a", "greater", "string_or_numeric"), s = N(t, "b", "greater", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Wa, o) } const nn = W({ greater_: B2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function H2(n, t) { let e = N(n, "a", "greaterEqual", "string_or_numeric"), s = N(t, "b", "greaterEqual", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(zr, o) } const to = W({ greaterEqual_: H2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _2(n) { const e = { input: N(n, "input", "imag") }; return L.runKernel(Cu, e) } const fd = W({ imag_: _2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function U2(n) { const e = { x: N(n, "x", "isFinite") }; return L.runKernel(Ar, e) } const Y2 = W({ isFinite_: U2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Q2(n) { const e = { x: N(n, "x", "isInf") }; return L.runKernel(Or, e) } const J2 = W({ isInf_: Q2 });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function j2(n) { const e = { x: N(n, "x", "isNaN") }; return L.runKernel(Pr, e) } const q2 = W({ isNaN_: j2 });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tv(n, t = .2) { const s = { x: N(n, "x", "leakyRelu") }, o = { alpha: t }; return L.runKernel(Ma, s, o) } const md = W({ leakyRelu_: tv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ev(n, t) { let e = N(n, "a", "less", "string_or_numeric"), s = N(t, "b", "less", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Fa, o) } const Gm = W({ less_: ev });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nv(n, t) { let e = N(n, "a", "lessEqual", "string_or_numeric"), s = N(t, "b", "lessEqual", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Va, o) } const Ko = W({ lessEqual_: nv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sv(n, t = 5, e = 1, s = 1, o = .5) {
        const r = N(n, "x", "localResponseNormalization"); v(r.rank === 4 || r.rank === 3, () => `Error in localResponseNormalization: x must be rank 3 or 4 but got
               rank ${r.rank}.`), v(Ro(t), () => `Error in localResponseNormalization: depthRadius must be an integer but got depthRadius ${t}.`); let i = r, a = !1; r.rank === 3 && (a = !0, i = D(r, [1, r.shape[0], r.shape[1], r.shape[2]])); const c = { x: i }, l = { depthRadius: t, bias: e, alpha: s, beta: o }, u = L.runKernel(Oa, c, l); return a ? D(u, [u.shape[1], u.shape[2], u.shape[3]]) : u
    } const ov = W({ localResponseNormalization_: sv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rv(n) { const e = { x: N(n, "x", "log", "float32") }; return L.runKernel(Kr, e) } const An = W({ log_: rv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function iv(n) { const e = { x: N(n, "x", "log1p") }; return L.runKernel(Zr, e) } const Lm = W({ log1p_: iv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function av(n, t) { v(Hl(n), () => "The f passed in variableGrads(f) must be a function"), v(t == null || Array.isArray(t) && t.every(l => l instanceof wc), () => "The varList passed in variableGrads(f, varList) must be an array of variables"); const e = t != null; if (!e) { t = []; for (const l in L.registeredVariables) t.push(L.registeredVariables[l]) } const s = e ? t.filter(l => !l.trainable) : null, o = t.length; t = t.filter(l => l.trainable), v(t.length > 0, () => `variableGrads() expects at least one of the input variables to be trainable, but none of the ${o} variables is trainable.`); const r = !0, { value: i, grads: a } = L.gradients(n, t, null, r); v(a.some(l => l != null), () => "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."), v(i.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${i.rank} tensor`); const c = {}; return t.forEach((l, u) => { a[u] != null && (c[l.name] = a[u]) }), s != null && s.forEach(l => c[l.name] = null), { value: i, grads: c } } function Zo(n) { return L.customGrad(n) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function cv(n) { const e = { x: N(n, "x", "neg") }; return L.runKernel(Ua, e) } const re = W({ neg_: cv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lv(n) { const e = { x: N(n, "x", "softplus") }; return L.runKernel(ii, e) } const Si = W({ softplus_: lv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function uv(n) { const t = N(n, "x", "logSigmoid"); return Zo(s => ({ value: re(Si(re(s))), gradFunc: i => E(i, Ao(re(s))) }))(t) } const dv = W({ logSigmoid_: uv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hv(n, t) { let e = N(n, "a", "sub"), s = N(t, "b", "sub");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(li, o) } const ft = W({ sub_: hv });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pv(n, t = -1) { const e = N(n, "logits", "logSoftmax"); if (t === -1 && (t = e.rank - 1), t !== e.rank - 1) throw Error(`Log Softmax along a non-last dimension is not yet supported. Logits was rank ${e.rank} and axis was ${t}`); return Zo((o, r) => { const a = Tn(o, t, !0), c = ft(o, a), l = ft(ot(c, "float32"), An(ut(ns(c), t, !0))); return r([l]), { value: l, gradFunc: (d, h) => { const [p] = h, f = !0, m = ns(p); return ft(d, E(ut(d, t, f), m)) } } })(e) } const Em = W({ logSoftmax_: pv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fv(n, t = null, e = !1) { const s = N(n, "x", "logSumExp"), o = It(t, s.shape), r = Tn(s, o, !0), i = ft(s, r), a = ns(i), c = ut(a, o), l = An(c), u = Q(D(r, l.shape), l); if (e) { const d = oe(u.shape, o); return D(u, d) } return u } const mv = W({ logSumExp_: fv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function gv(n, t) { const e = N(n, "a", "logicalAnd", "bool"), s = N(t, "b", "logicalAnd", "bool"); gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(za, o) } const ss = W({ logicalAnd_: gv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bv(n) { const e = { x: N(n, "x", "logicalNot", "bool") }; return L.runKernel(Xa, e) } const gd = W({ logicalNot_: bv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function xv(n, t) { const e = N(n, "a", "logicalOr", "bool"), s = N(t, "b", "logicalOr", "bool"); gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Aa, o) } const Dm = W({ logicalOr_: xv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yv(n, t) { const e = N(n, "a", "logicalXor", "bool"), s = N(t, "b", "logicalXor", "bool"); return gt(e.shape, s.shape), ss(Dm(n, t), gd(ss(n, t))) } const Iv = W({ logicalXor_: yv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Cv(n, t, e, s, o) { const r = N(n, "x", "maxPool"), i = 1; let a = r, c = !1; r.rank === 3 && (c = !0, a = D(r, [1, r.shape[0], r.shape[1], r.shape[2]])), v(a.rank === 4, () => `Error in maxPool: input must be rank 4 but got rank ${a.rank}.`), v(Te(e, i), () => `Error in maxPool: Either strides or dilations must be 1. Got strides ${e} and dilations '${i}'`), Fe("maxPool", s, o); const l = { x: a }, u = { filterSize: t, strides: e, pad: s, dimRoundingMode: o }, d = L.runKernel(Ka, l, u); return c ? D(d, [d.shape[1], d.shape[2], d.shape[3]]) : d } const bd = W({ maxPool_: Cv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function wv(n, t = [1, 1, 1], e, s, o, r = "NDHWC") { const i = N(n, "x", "maxPool3d"); let a = i, c = !1; i.rank === 4 && (c = !0, a = D(i, [1, i.shape[0], i.shape[1], i.shape[2], i.shape[3]])), v(a.rank === 5, () => `Error in maxPool3d: x must be rank 5 but got rank ${a.rank}.`), v(r === "NDHWC", () => `Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of ${r}`), Fe("maxPool3d", s, o); const l = { x: a }, u = { filterSize: t, strides: e, pad: s, dimRoundingMode: o, dataFormat: r }, d = L.runKernel(Za, l, u); return c ? D(d, [d.shape[1], d.shape[2], d.shape[3], d.shape[4]]) : d } const vv = W({ maxPool3d_: wv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Sv(n, t) { let e = N(n, "a", "maximum"), s = N(t, "b", "maximum");[e, s] = qt(e, s), e.dtype === "bool" && (e = ot(e, "int32"), s = ot(s, "int32")), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Br, o) } const Is = W({ maximum_: Sv });/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kv(n, t = null, e = !1) { const o = { x: N(n, "x", "mean") }, r = { axis: t, keepDims: e }; return L.runKernel(Ba, o, r) } const ie = W({ mean_: kv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function me(n, t = "float32") { if (jn(n), t === "complex64") { const s = me(n, "float32"), o = me(n, "float32"); return Vo(s, o) } const e = Se(Z(n), t); return L.makeTensor(e, n, t) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function eo(n, t = "float32") { if (jn(n), t === "complex64") { const s = eo(n, "float32"), o = me(n, "float32"); return Vo(s, o) } const e = Ul(Z(n), t); return L.makeTensor(e, n, t) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Tv(n, t) { let e = N(n, "a", "minimum"), s = N(t, "b", "minimum");[e, s] = qt(e, s), e.dtype === "bool" && (e = ot(e, "int32"), s = ot(s, "int32")), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Hr, o) } const xd = W({ minimum_: Tv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Nv(n, t, e) { v(e === "reflect" || e === "symmetric", () => `Invalid mode. Mode must be either reflect or symmetric. Got ${e}.`); const s = N(n, "x", "mirrorPad"); if (s.rank === 0) throw new Error("mirrorPad(scalar) is not defined. Pass non-scalar to mirrorPad"); v(t.length === s.rank, () => `Padding doesn't match input. Must be ${s.rank}. Got ${t.length}.`); const o = e === "reflect" ? 1 : 0; for (let a = 0; a < s.rank; a++)v(t[a].length === 2, () => "Invalid number of paddings. Must be length of 2 each."), v(t[a][0] >= 0 && t[a][0] <= s.shape[a] - o && t[a][1] >= 0 && t[a][1] <= s.shape[a] - o, () => `Padding in dimension ${a} cannot be greater than or equal to ${s.shape[a] - o} or less than 0 for input of shape ${s.shape}`); const r = { paddings: t, mode: e }, i = { x: s }; return L.runKernel(_a, i, r) } const Rv = W({ mirrorPad_: Nv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $v(n, t) { let e = N(n, "a", "mod"), s = N(t, "b", "mod");[e, s] = qt(e, s); const o = { a: e, b: s }; return L.runKernel(_r, o) } const Gv = W({ mod_: $v });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Lv(n, t = null, e = !1) { n = N(n, "x", "moments"); const s = It(t, n.shape), o = ie(n, s, e); let r = o.shape; e || (r = oe(o.shape, s)); const i = Zt(ft(ot(n, "float32"), D(o, r))), a = ie(i, s, e); return { mean: o, variance: a } } const yd = W({ moments_: Lv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ev(n, t) { let e = N(n, "a", "notEqual", "string_or_numeric"), s = N(t, "b", "notEqual", "string_or_numeric");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }; return L.runKernel(Ya, o) } const Gc = W({ notEqual_: Ev });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Dv(n, t, e = 1, s = 0, o = "int32") { if (t < 2) throw new Error(`Error in oneHot: depth must be >=2, but it is ${t}`); const i = { indices: N(n, "indices", "oneHot", "int32") }, a = { dtype: o, depth: t, onValue: e, offValue: s }; return L.runKernel(Ja, i, a) } const Wm = W({ oneHot_: Dv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Wv(n) { const e = { x: N(n, "x", "onesLike") }; return L.runKernel(Qa, e) } const pn = W({ onesLike_: Wv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Mv(n, t, e = 0) { const s = N(n, "x", "pad"); if (s.rank === 0) throw new Error("pad(scalar) is not defined. Pass non-scalar to pad"); const o = { paddings: t, constantValue: e }, r = { x: s }; return L.runKernel(qa, r, o) } const Id = W({ pad_: Mv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Fv(n, t, e) { const s = N(n, "x", "spaceToBatchND"); v(s.rank >= 1 + t.length, () => `input rank ${s.rank} should be > than [blockShape] ${t.length}`), v(e.length === t.length, () => `paddings.shape[0] ${e.length} must be equal to [blockShape] ${t.length}`), v(s.shape.reduce((i, a, c) => c > 0 && c <= t.length ? i && (a + e[c - 1][0] + e[c - 1][1]) % t[c - 1] === 0 : i, !0), () => `input spatial dimensions ${s.shape.slice(1)} with paddings ${e.toString()} must be divisible by blockShapes ${t.toString()}`); const o = { x: s }, r = { blockShape: t, paddings: e }; return L.runKernel(lc, o, r) } const Cd = W({ spaceToBatchND_: Fv });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Vv(n, t, e, s, o, r, i) { o == null && (o = [1, 1]), r == null && (r = 1), s === 0 && (s = "valid"); const a = N(n, "x", "maxPool"); let c = a, l = !1; a.rank === 3 && (l = !0, c = D(a, [1, a.shape[0], a.shape[1], a.shape[2]])), v(Te(r, o), () => `Error in pool: Either strides or dilations must be 1. Got strides ${r} and dilations '${o}'`); const u = hn(c.shape, t, r, o, s), d = [u.dilationHeight, u.dilationWidth]; let h; s === "same" ? h = Xv([u.filterHeight, u.filterWidth], d) : h = [[0, 0], [0, 0]]; const p = d[0] === 1 && d[1] === 1, [f, m] = zv([u.inHeight, u.inWidth], d, h), g = p ? s : "valid", b = p ? c : Cd(c, d, f), I = (e === "avg" ? () => rd(b, t, r, g, i) : () => bd(b, t, r, g, i))(), y = p ? I : ad(I, d, m); return l ? D(y, [y.shape[1], y.shape[2], y.shape[3]]) : y } function zv(n, t, e) { const s = e.map(u => u[0]), o = e.map(u => u[1]), r = n.concat(s, o), i = t.map((u, d) => (u - r[d] % u) % u), a = o.map((u, d) => u + i[d]), c = t.map((u, d) => [s[d], a[d]]), l = t.map((u, d) => [0, i[d]]); return [c, l] } function Xv(n, t) { const s = n.map((i, a) => i + (i - 1) * (t[a] - 1)).map(i => i - 1), o = s.map(i => Math.floor(i / 2)), r = s.map((i, a) => i - o[a]); return s.map((i, a) => [o[a], r[a]]) } const Av = W({ pool_: Vv });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ov(n, t) { const e = N(n, "x", "prelu"), s = N(t, "alpha", "prelu"), o = { x: e, alpha: s }; return L.runKernel(tc, o) } const wd = W({ prelu_: Ov });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Pv(n, t = null, e = !1) { let s = N(n, "x", "prod"); s.dtype === "bool" && (s = ot(s, "int32")); const o = { x: s }, r = { axis: t, keepDims: e }; return L.runKernel(ec, o, r) } const Kv = W({ prod_: Pv }); var vd = { exports: {} }; vd.exports, function (n) { (function (t, e, s) { function o(c) { var l = this, u = a(); l.next = function () { var d = 2091639 * l.s0 + l.c * 23283064365386963e-26; return l.s0 = l.s1, l.s1 = l.s2, l.s2 = d - (l.c = d | 0) }, l.c = 1, l.s0 = u(" "), l.s1 = u(" "), l.s2 = u(" "), l.s0 -= u(c), l.s0 < 0 && (l.s0 += 1), l.s1 -= u(c), l.s1 < 0 && (l.s1 += 1), l.s2 -= u(c), l.s2 < 0 && (l.s2 += 1), u = null } function r(c, l) { return l.c = c.c, l.s0 = c.s0, l.s1 = c.s1, l.s2 = c.s2, l } function i(c, l) { var u = new o(c), d = l && l.state, h = u.next; return h.int32 = function () { return u.next() * 4294967296 | 0 }, h.double = function () { return h() + (h() * 2097152 | 0) * 11102230246251565e-32 }, h.quick = h, d && (typeof d == "object" && r(d, u), h.state = function () { return r(u, {}) }), h } function a() { var c = 4022871197, l = function (u) { u = String(u); for (var d = 0; d < u.length; d++) { c += u.charCodeAt(d); var h = .02519603282416938 * c; c = h >>> 0, h -= c, h *= c, c = h >>> 0, h -= c, c += h * 4294967296 } return (c >>> 0) * 23283064365386963e-26 }; return l } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.alea = i })(As, n, !1) }(vd); var Zv = vd.exports, Sd = { exports: {} }; Sd.exports, function (n) { (function (t, e, s) { function o(a) { var c = this, l = ""; c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.next = function () { var d = c.x ^ c.x << 11; return c.x = c.y, c.y = c.z, c.z = c.w, c.w ^= c.w >>> 19 ^ d ^ d >>> 8 }, a === (a | 0) ? c.x = a : l += a; for (var u = 0; u < l.length + 64; u++)c.x ^= l.charCodeAt(u) | 0, c.next() } function r(a, c) { return c.x = a.x, c.y = a.y, c.z = a.z, c.w = a.w, c } function i(a, c) { var l = new o(a), u = c && c.state, d = function () { return (l.next() >>> 0) / 4294967296 }; return d.double = function () { do var h = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (h + p) / (1 << 21); while (f === 0); return f }, d.int32 = l.next, d.quick = d, u && (typeof u == "object" && r(u, l), d.state = function () { return r(l, {}) }), d } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.xor128 = i })(As, n, !1) }(Sd); var Bv = Sd.exports, kd = { exports: {} }; kd.exports, function (n) { (function (t, e, s) { function o(a) { var c = this, l = ""; c.next = function () { var d = c.x ^ c.x >>> 2; return c.x = c.y, c.y = c.z, c.z = c.w, c.w = c.v, (c.d = c.d + 362437 | 0) + (c.v = c.v ^ c.v << 4 ^ (d ^ d << 1)) | 0 }, c.x = 0, c.y = 0, c.z = 0, c.w = 0, c.v = 0, a === (a | 0) ? c.x = a : l += a; for (var u = 0; u < l.length + 64; u++)c.x ^= l.charCodeAt(u) | 0, u == l.length && (c.d = c.x << 10 ^ c.x >>> 4), c.next() } function r(a, c) { return c.x = a.x, c.y = a.y, c.z = a.z, c.w = a.w, c.v = a.v, c.d = a.d, c } function i(a, c) { var l = new o(a), u = c && c.state, d = function () { return (l.next() >>> 0) / 4294967296 }; return d.double = function () { do var h = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (h + p) / (1 << 21); while (f === 0); return f }, d.int32 = l.next, d.quick = d, u && (typeof u == "object" && r(u, l), d.state = function () { return r(l, {}) }), d } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.xorwow = i })(As, n, !1) }(kd); var Hv = kd.exports, Td = { exports: {} }; Td.exports, function (n) { (function (t, e, s) { function o(a) { var c = this; c.next = function () { var u = c.x, d = c.i, h, p; return h = u[d], h ^= h >>> 7, p = h ^ h << 24, h = u[d + 1 & 7], p ^= h ^ h >>> 10, h = u[d + 3 & 7], p ^= h ^ h >>> 3, h = u[d + 4 & 7], p ^= h ^ h << 7, h = u[d + 7 & 7], h = h ^ h << 13, p ^= h ^ h << 9, u[d] = p, c.i = d + 1 & 7, p }; function l(u, d) { var h, p = []; if (d === (d | 0)) p[0] = d; else for (d = "" + d, h = 0; h < d.length; ++h)p[h & 7] = p[h & 7] << 15 ^ d.charCodeAt(h) + p[h + 1 & 7] << 13; for (; p.length < 8;)p.push(0); for (h = 0; h < 8 && p[h] === 0; ++h); for (h == 8 ? p[7] = -1 : p[h], u.x = p, u.i = 0, h = 256; h > 0; --h)u.next() } l(c, a) } function r(a, c) { return c.x = a.x.slice(), c.i = a.i, c } function i(a, c) { a == null && (a = +new Date); var l = new o(a), u = c && c.state, d = function () { return (l.next() >>> 0) / 4294967296 }; return d.double = function () { do var h = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (h + p) / (1 << 21); while (f === 0); return f }, d.int32 = l.next, d.quick = d, u && (u.x && r(u, l), d.state = function () { return r(l, {}) }), d } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.xorshift7 = i })(As, n, !1) }(Td); var _v = Td.exports, Nd = { exports: {} }; Nd.exports, function (n) { (function (t, e, s) { function o(a) { var c = this; c.next = function () { var u = c.w, d = c.X, h = c.i, p, f; return c.w = u = u + 1640531527 | 0, f = d[h + 34 & 127], p = d[h = h + 1 & 127], f ^= f << 13, p ^= p << 17, f ^= f >>> 15, p ^= p >>> 12, f = d[h] = f ^ p, c.i = h, f + (u ^ u >>> 16) | 0 }; function l(u, d) { var h, p, f, m, g, b = [], x = 128; for (d === (d | 0) ? (p = d, d = null) : (d = d + "\0", p = 0, x = Math.max(x, d.length)), f = 0, m = -32; m < x; ++m)d && (p ^= d.charCodeAt((m + 32) % d.length)), m === 0 && (g = p), p ^= p << 10, p ^= p >>> 15, p ^= p << 4, p ^= p >>> 13, m >= 0 && (g = g + 1640531527 | 0, h = b[m & 127] ^= p + g, f = h == 0 ? f + 1 : 0); for (f >= 128 && (b[(d && d.length || 0) & 127] = -1), f = 127, m = 4 * 128; m > 0; --m)p = b[f + 34 & 127], h = b[f = f + 1 & 127], p ^= p << 13, h ^= h << 17, p ^= p >>> 15, h ^= h >>> 12, b[f] = p ^ h; u.w = g, u.X = b, u.i = f } l(c, a) } function r(a, c) { return c.i = a.i, c.w = a.w, c.X = a.X.slice(), c } function i(a, c) { a == null && (a = +new Date); var l = new o(a), u = c && c.state, d = function () { return (l.next() >>> 0) / 4294967296 }; return d.double = function () { do var h = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (h + p) / (1 << 21); while (f === 0); return f }, d.int32 = l.next, d.quick = d, u && (u.X && r(u, l), d.state = function () { return r(l, {}) }), d } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.xor4096 = i })(As, n, !1) }(Nd); var Uv = Nd.exports, Rd = { exports: {} }; Rd.exports, function (n) { (function (t, e, s) { function o(a) { var c = this, l = ""; c.next = function () { var d = c.b, h = c.c, p = c.d, f = c.a; return d = d << 25 ^ d >>> 7 ^ h, h = h - p | 0, p = p << 24 ^ p >>> 8 ^ f, f = f - d | 0, c.b = d = d << 20 ^ d >>> 12 ^ h, c.c = h = h - p | 0, c.d = p << 16 ^ h >>> 16 ^ f, c.a = f - d | 0 }, c.a = 0, c.b = 0, c.c = -1640531527, c.d = 1367130551, a === Math.floor(a) ? (c.a = a / 4294967296 | 0, c.b = a | 0) : l += a; for (var u = 0; u < l.length + 20; u++)c.b ^= l.charCodeAt(u) | 0, c.next() } function r(a, c) { return c.a = a.a, c.b = a.b, c.c = a.c, c.d = a.d, c } function i(a, c) { var l = new o(a), u = c && c.state, d = function () { return (l.next() >>> 0) / 4294967296 }; return d.double = function () { do var h = l.next() >>> 11, p = (l.next() >>> 0) / 4294967296, f = (h + p) / (1 << 21); while (f === 0); return f }, d.int32 = l.next, d.quick = d, u && (typeof u == "object" && r(u, l), d.state = function () { return r(l, {}) }), d } e && e.exports ? e.exports = i : s && s.amd ? s(function () { return i }) : this.tychei = i })(As, n, !1) }(Rd); var Yv = Rd.exports, Mm = { exports: {} }; const Qv = tC(Object.freeze(Object.defineProperty({ __proto__: null, default: {} }, Symbol.toStringTag, { value: "Module" }))); (function (n) { (function (t, e, s) { var o = 256, r = 6, i = 52, a = "random", c = s.pow(o, r), l = s.pow(2, i), u = l * 2, d = o - 1, h; function p(y, C, w) { var k = []; C = C == !0 ? { entropy: !0 } : C || {}; var S = b(g(C.entropy ? [y, I(e)] : y ?? x(), 3), k), T = new f(k), R = function () { for (var G = T.g(r), F = c, V = 0; G < l;)G = (G + V) * o, F *= o, V = T.g(1); for (; G >= u;)G /= 2, F /= 2, V >>>= 1; return (G + V) / F }; return R.int32 = function () { return T.g(4) | 0 }, R.quick = function () { return T.g(4) / 4294967296 }, R.double = R, b(I(T.S), e), (C.pass || w || function (G, F, V, z) { return z && (z.S && m(z, T), G.state = function () { return m(T, {}) }), V ? (s[a] = G, F) : G })(R, S, "global" in C ? C.global : this == s, C.state) } function f(y) { var C, w = y.length, k = this, S = 0, T = k.i = k.j = 0, R = k.S = []; for (w || (y = [w++]); S < o;)R[S] = S++; for (S = 0; S < o; S++)R[S] = R[T = d & T + y[S % w] + (C = R[S])], R[T] = C; (k.g = function (G) { for (var F, V = 0, z = k.i, X = k.j, O = k.S; G--;)F = O[z = d & z + 1], V = V * o + O[d & (O[z] = O[X = d & X + F]) + (O[X] = F)]; return k.i = z, k.j = X, V })(o) } function m(y, C) { return C.i = y.i, C.j = y.j, C.S = y.S.slice(), C } function g(y, C) { var w = [], k = typeof y, S; if (C && k == "object") for (S in y) try { w.push(g(y[S], C - 1)) } catch { } return w.length ? w : k == "string" ? y : y + "\0" } function b(y, C) { for (var w = y + "", k, S = 0; S < w.length;)C[d & S] = d & (k ^= C[d & S] * 19) + w.charCodeAt(S++); return I(C) } function x() { try { var y; return h && (y = h.randomBytes) ? y = y(o) : (y = new Uint8Array(o), (t.crypto || t.msCrypto).getRandomValues(y)), I(y) } catch { var C = t.navigator, w = C && C.plugins; return [+new Date, t, w, t.screen, I(e)] } } function I(y) { return String.fromCharCode.apply(0, y) } if (b(s.random(), e), n.exports) { n.exports = p; try { h = Qv } catch { } } else s["seed" + a] = p })(typeof self < "u" ? self : As, [], Math) })(Mm); var Jv = Mm.exports, jv = Zv, qv = Bv, tS = Hv, eS = _v, nS = Uv, sS = Yv, no = Jv; no.alea = jv, no.xor128 = qv, no.xorwow = tS, no.xorshift7 = eS, no.xor4096 = nS, no.tychei = sS; var $d = no;/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Fm { constructor(t, e, s, o, r) { this.mean = t, this.stdDev = e, this.dtype = s, this.nextVal = NaN, this.truncated = o, this.truncated && (this.upper = this.mean + this.stdDev * 2, this.lower = this.mean - this.stdDev * 2); const i = r || Math.random(); this.random = $d.alea(i.toString()) } nextValue() { if (!isNaN(this.nextVal)) { const o = this.nextVal; return this.nextVal = NaN, o } let t, e, s = !1; for (; !s;) { let o, r, i; do o = 2 * this.random() - 1, r = 2 * this.random() - 1, i = o * o + r * r; while (i >= 1 || i === 0); const a = Math.sqrt(-2 * Math.log(i) / i); t = this.mean + this.stdDev * o * a, e = this.mean + this.stdDev * r * a, (!this.truncated || this.isValidTruncated(t)) && (s = !0) } return (!this.truncated || this.isValidTruncated(e)) && (this.nextVal = this.convertValue(e)), this.convertValue(t) } convertValue(t) { return this.dtype == null || this.dtype === "float32" ? t : Math.round(t) } isValidTruncated(t) { return t <= this.upper && t >= this.lower } } class oS { constructor(t = 0, e = 1, s, o) { if (this.canReturnFloat = () => this.dtype == null || this.dtype === "float32", this.min = t, this.range = e - t, this.dtype = s, o == null && (o = Math.random()), typeof o == "number" && (o = o.toString()), !this.canReturnFloat() && this.range <= 1) throw new Error(`The difference between ${t} - ${e} <= 1 and dtype is not float`); this.random = $d.alea(o) } convertValue(t) { return this.canReturnFloat() ? t : Math.round(t) } nextValue() { return this.convertValue(this.min + this.range * this.random()) } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rS(n, t = 0, e = 1, s, o) { if (jn(n), s != null && s === "bool") throw new Error(`Unsupported data type ${s}`); const r = new Fm(t, e, s, !1, o), i = Ct(n, s); for (let a = 0; a < i.values.length; a++)i.values[a] = r.nextValue(); return i.toTensor() } const iS = W({ randomNormal_: rS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aS(n, t = 0, e = 1, s = "float32", o) { jn(n); const r = Ct(n, s), i = new oS(t, e, null, o); for (let a = 0; a < r.values.length; a++)r.values[a] = i.nextValue(); return r.toTensor() } const Lc = W({ randomUniform_: aS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ki(n, t, e = 1, s = "float32") { if (e === 0) throw new Error("Cannot have a step of zero"); const o = { start: n, stop: t, step: e, dtype: s }; return L.runKernel(Ru, {}, o) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function cS(n) { const e = { input: N(n, "input", "real") }; return L.runKernel($u, e) } const Ec = W({ real_: cS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lS(n) { const e = { x: N(n, "x", "reciprocal") }; return L.runKernel(Qr, e) } const uS = W({ reciprocal_: lS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dS(n) { const e = { x: N(n, "x", "relu") }; return L.runKernel(Jr, e) } const so = W({ relu_: dS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hS(n) { const e = { x: N(n, "x", "relu6") }; return L.runKernel(jr, e) } const Vm = W({ relu6_: hS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pS(n, t) { const s = { x: N(n, "x", "reverse") }, o = { dims: t }; return L.runKernel(rc, s, o) } const oo = W({ reverse_: pS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fS(n) { const e = { x: N(n, "x", "round") }; return L.runKernel(qr, e) } const zm = W({ round_: fS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mS(n) { const e = { x: N(n, "x", "rsqrt", "float32") }; return L.runKernel(ti, e) } const Xm = W({ rsqrt_: mS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function gS(n) { const e = { x: N(n, "x", "selu") }; return L.runKernel(ei, e) } const Am = W({ selu_: gS }); function bS(n, t, e, s, o, r = [1, 1], i = "NHWC") { const a = N(n, "x", "separableConv2d"), c = N(t, "depthwiseFilter", "separableConv2d"), l = N(e, "pointwiseFilter", "separableConv2d"); let u = a, d = !1; if (a.rank === 3 && (d = !0, u = D(a, [1, a.shape[0], a.shape[1], a.shape[2]])), i === "NCHW") throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported"); v(u.rank === 4, () => `Error in separableConv2d: input must be rank 4, but got rank ${u.rank}.`), v(c.rank === 4, () => `Error in separableConv2d: depthwise filter must be rank 4, but got rank ${c.rank}.`), v(l.rank === 4, () => `Error in separableConv2d: pointwise filter must be rank 4, but got rank ${c.rank}.`), v(l.shape[0] === 1, () => `Error in separableConv2d: the first dimension of pointwise filter  must be 1, but got ${l.shape[0]}.`), v(l.shape[1] === 1, () => `Error in separableConv2d: the second dimension of pointwise filter must be 1, but got ${l.shape[1]}.`); const h = c.shape[2], p = c.shape[3]; v(l.shape[2] === h * p, () => `Error in separableConv2d: the third dimension of pointwise filter must be ${h * p}, but got ${l.shape[2]}.`); const f = dd(u, c, s, o, i, r), g = qs(f, l, 1, "valid", i); return d ? D(g, [g.shape[1], g.shape[2], g.shape[3]]) : g } const Om = W({ separableConv2d_: bS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function xS(n) { const e = { x: N(n, "x", "sign") }; return L.runKernel(oi, e) } const yS = W({ sign_: xS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function IS(n) { const e = { x: N(n, "x", "sin", "float32") }; return L.runKernel(ni, e) } const Pm = W({ sin_: IS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function CS(n) { const e = { x: N(n, "x", "sinh") }; return L.runKernel(si, e) } const Km = W({ sinh_: CS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function wS(n, t, e) { const s = N(n, "x", "slice1d"); return v(s.rank === 1, () => `slice1d expects a rank-1 tensor, but got a rank-${s.rank} tensor`), Vt(s, [t], [e]) } const Gd = W({ slice1d_: wS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function vS(n, t, e) { const s = N(n, "x", "slice2d"); return v(s.rank === 2, () => `slice2d expects a rank-2 tensor, but got a rank-${s.rank} tensor`), Vt(s, t, e) } const Zm = W({ slice2d_: vS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function SS(n, t, e) { const s = N(n, "x", "slice3d"); return v(s.rank === 3, () => `slice3d expects a rank-3 tensor, but got a rank-${s.rank} tensor`), Vt(s, t, e) } const Ld = W({ slice3d_: SS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kS(n, t, e) { const s = N(n, "x", "slice4d"); return v(s.rank === 4, () => `slice4d expects a rank-4 tensor, but got a rank-${s.rank} tensor`), Vt(s, t, e) } const Dc = W({ slice4d_: kS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function TS(n, t = -1) { const e = N(n, "logits", "softmax", "float32"); if (t === -1 && (t = e.rank - 1), t !== e.rank - 1) throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${e.rank} and dim was ${t}`); const s = { logits: e }, o = { dim: t }; return L.runKernel(dc, s, o) } const Ed = W({ softmax_: TS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function NS(n) { v(n.dtype === "complex64", () => `The dtype for tf.spectral.fft() must be complex64 but got ${n.dtype}.`); const t = { input: n }; return L.runKernel(bu, t) } const Bm = W({ fft_: NS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function RS(n) { v(n.dtype === "complex64", () => `The dtype for tf.spectral.ifft() must be complex64 but got ${n.dtype}.`); const t = { input: n }; return L.runKernel(Iu, t) } const Dd = W({ ifft_: RS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $S(n) { const t = n.shape[n.shape.length - 1], e = n.size / t; let s; if (t <= 2) { const o = D(n, [e, t]); s = Dd(o) } else { const o = [e, 2 * (t - 1)], r = D(Ec(n), [e, t]), i = D(fd(n), [e, t]), a = oo(Vt(r, [0, 1], [e, t - 2]), 1), c = E(oo(Vt(i, [0, 1], [e, t - 2]), 1), Gt(-1)), l = Ve([r, a], 1), u = Ve([i, c], 1), d = D(Vo(l, u), [o[0], o[1]]); s = Dd(d) } if (s = Ec(s), n.rank === 3 && n.shape[0] !== 0) { const o = s, r = n.shape[0]; s = D(s, [r, s.shape[0] / r, s.shape[1]]), o.dispose() } return s } const GS = W({ irfft_: $S });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function LS(n, t, e = 0) { const o = { x: N(n, "x", "split") }, r = { numOrSizeSplits: t, axis: e }; return L.runKernel(uc, o, r) } const sn = W({ split_: LS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ES(n, t) { v(n.dtype === "float32", () => `The dtype for rfft() must be real value but got ${n.dtype}`); let e = n.shape[n.shape.length - 1]; const s = n.size / e; let o; if (t != null && t < e) { const f = n.shape.map(g => 0), m = n.shape.map(g => g); m[n.shape.length - 1] = t, o = Vt(n, f, m), e = t } else if (t != null && t > e) { const f = n.shape.map(m => m); f[n.shape.length - 1] = t - e, o = Ve([n, me(f)], n.shape.length - 1), e = t } else o = n; const r = kt(o), i = D(Vo(o, r), [s, e]), a = Bm(i), c = Math.floor(e / 2) + 1, l = Ec(a), u = fd(a), d = sn(l, [c, e - c], l.shape.length - 1), h = sn(u, [c, e - c], u.shape.length - 1), p = o.shape.slice(); return p[o.shape.length - 1] = c, D(Vo(d[0], h[0]), p) } const DS = W({ rfft_: ES });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function WS(n, t) { let e = N(n, "a", "squaredDifference"), s = N(t, "b", "squaredDifference");[e, s] = qt(e, s), gt(e.shape, s.shape); const o = { a: e, b: s }, r = {}; return L.runKernel(ci, o, r) } const MS = W({ squaredDifference_: WS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function FS(n, t) { const e = N(n, "x", "squeeze", "string_or_numeric"); return D(e, ds(e.shape, t).newShape) } const Ti = W({ squeeze_: FS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function VS(n, t = 0) { const e = im(n, "tensors", "stack", "string_or_numeric"); v(e.length >= 1, () => "Pass at least one tensor to tf.stack"), e.length > 0 && v(t <= e[0].rank, () => "Axis must be <= rank of the tensor"); const s = e, o = { axis: t }; return L.runKernel(ja, s, o) } const os = W({ stack_: VS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function zS(n, t = 0) { const s = { x: N(n, "x", "step") }, o = { alpha: t }; return L.runKernel(pi, s, o) } const Ni = W({ step_: zS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function XS(n, t, e, s, o = 0, r = 0, i = 0, a = 0, c = 0) { const u = { x: N(n, "x", "stridedSlice", "string_or_numeric") }, d = { begin: t, end: e, strides: s, beginMask: o, endMask: r, ellipsisMask: i, newAxisMask: a, shrinkAxisMask: c }; return L.runKernel(Du, u, d) } const AS = W({ stridedSlice_: XS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function OS(n) { const e = { x: N(n, "x", "tan", "float32") }; return L.runKernel(ui, e) } const PS = W({ tan_: OS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function on(n, t) { Kl(n); const e = bi(n, t); if (e.length !== 1) throw new Error("tensor1d() requires values to be a flat/TypedArray"); return xi(n, null, e, t) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Wd(n, t, e) { if (Kl(n), t != null && t.length !== 2) throw new Error("tensor2d() requires shape to have two numbers"); const s = bi(n, e); if (s.length !== 2 && s.length !== 1) throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray"); if (s.length === 1 && t == null) throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray"); return xi(n, t, s, e) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function KS(n, t, e) { if (Kl(n), t != null && t.length !== 3) throw new Error("tensor3d() requires shape to have three numbers"); const s = bi(n, e); if (s.length !== 3 && s.length !== 1) throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray"); if (s.length === 1 && t == null) throw new Error("tensor3d() requires shape to be provided when `values` are a flat array"); return xi(n, t, s, e) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ZS(n, t = 1, e = !0) { const s = N(n, "x", "topk"); if (s.rank === 0) throw new Error("topk() expects the input to be of rank 1 or higher"); const o = s.shape[s.shape.length - 1]; if (t < 0) throw new Error(`'k' passed to topk() must be >= 0 but got ${t}`); if (t > o) throw new Error(`'k' passed to topk() must be <= the last dimension (${o}) but got ${t}`); const r = { x: s }, i = { k: t, sorted: e }, [a, c] = L.runKernel(Wu, r, i); return { values: a, indices: c } } const BS = W({ topk_: ZS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function HS(n, t = 0, e = 1, s, o) { if (jn(n), s != null && s === "bool") throw new Error("Unsupported data type $ { dtype }"); const r = new Fm(t, e, s, !0, o), i = Ct(n, s); for (let a = 0; a < i.values.length; a++)i.values[a] = r.nextValue(); return i.toTensor() } const Hm = W({ truncatedNormal_: HS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _S(n, t = 0) { const e = N(n, "x", "unique", "string_or_numeric"); v(e.rank > 0, () => "The input tensor must be at least 1D"); const s = { x: e }, o = { axis: t }, [r, i] = L.runKernel(Fu, s, o); return { values: r, indices: i } } const US = W({ unique_: _S });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function YS(n, t, e) { const s = N(n, "x", "unsortedSegmentSum"), o = N(t, "segmentIds", "unsortedSegmentSum", "int32"); v(Ro(e), () => "numSegments must be of dtype int"); const r = { x: s, segmentIds: o }, i = { numSegments: e }; return L.runKernel(pc, r, i) } const _m = W({ unsortedSegmentSum_: YS });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QS(n, t = 0) { const e = N(n, "x", "unstack", "string_or_numeric"); v(t >= -e.shape.length && t < e.shape.length, () => `Axis = ${t} is not in [-${e.shape.length}, ${e.shape.length})`); const s = { value: e }, o = { axis: t }; return L.runKernel(hc, s, o) } const ro = W({ unstack_: QS });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JS(n, t = !0, e, s) { return L.makeVariable(n, t, e, s) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Um(n, t) { const e = []; for (let r = 0; r < t.length; r++)t[r] && e.push(r); const s = Ct(n, "int32"), o = Ct([e.length, n.length], "int32"); for (let r = 0; r < e.length; r++) { const i = s.indexToLoc(e[r]), a = r * n.length; o.values.set(i, a) } return o.toTensor() }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jS(n, t, e) { const s = N(n, "x", "transpose"); if (t == null && (t = s.shape.map((i, a) => a).reverse()), v(s.rank === t.length, () => `Error in transpose: rank of input ${s.rank} must match length of perm ${t}.`), t.forEach(i => { v(i >= 0 && i < s.rank, () => `All entries in 'perm' must be between 0 and ${s.rank - 1} but got ${t}`) }), s.rank <= 1) return s.clone(); const o = { x: s }, r = { perm: t }; return s.dtype === "complex64" ? M(() => { let i = Ec(s), a = fd(s); return i = L.runKernel(Eo, { x: i }, r), a = L.runKernel(Eo, { x: a }, r), e && (a = re(a)), Vo(i, a) }) : L.runKernel(Eo, o, r) } const St = W({ transpose_: jS }); function Ym(n, t, e) { const s = t.rank > 1 ? t.shape[t.rank - 1] : 1, o = t.rank > 1 ? t.rank - 1 : 1, r = `Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: ${e.shape}, indices.shape: ${t.shape}, shape: ${n}, sliceDim: ${s}, and batchDim: ${o}.`; if (e.rank < o) throw new Error(r + ` update.rank < ${o}. `); if (n.length < s + (e.rank - o)) throw new Error(r + ` Output shape length < ${s + (e.rank - o)}`); if (e.rank !== o + n.length - s) throw new Error(r + ` update.rank != ${o + n.length - s}`); for (let i = 0; i < o; ++i)if (e.shape[i] !== t.shape[i]) throw new Error(r + ` updates.shape[${i}] (${e.shape[i]}) != indices.shape[${i}] (${t.shape[i]}).`); for (let i = 0; i < e.rank - o; ++i)if (e.shape[i + o] !== n[i + s]) throw new Error(r + ` updates.shape[${i + o}] (${e.shape[i + o]}) != shape[${i + o}] (${n[i + o]})`) } function qS(n, t, e) { if (t.rank < 1) throw new Error(`tf.scatterND() expects the indices to be rank 1 or higher, but the rank was ${t.rank}.`); if (n.rank < 1) throw new Error(`tf.scatterND() expects the updates to be rank 1 or higher, but the rank was ${n.rank}.`); if (t.dtype !== "int32") throw new Error(`The dtype of 'indices' should be int32, but got dtype: ${t.dtype}`); if (e.length < 1) throw new Error(`Output rank must be greater or equal to 1, but got shape: ${e}`); if (e.length === 0) { if (t.size === 0) throw new Error(`Indices specified for empty output. indices shape: ${t.shape}`); if (n.size === 0) throw new Error(`Updates specified for empty output. updates shape: ${n.shape}`) } Ym(e, t, n) } function Ri(n, t, e) { const s = t.shape.length, o = s > 1 ? t.shape[s - 1] : 1, r = e.length; let i = 1; for (let d = o; d < r; ++d)i *= e[d]; const a = o < 1 ? 1 : o, c = Z(t.shape) / a, l = [...ct(e.slice(0, o)), 1], u = Z(e); return { sliceRank: o, numUpdates: c, sliceSize: i, strides: l, outputSize: u } }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tk(n, t) { if (t == null) return n.shape.slice(); if (Rt(n.shape, t)) return t; if (n.shape.length === t.length) { const e = []; for (let s = 0; s < n.shape.length; s++)t[s] == null && n.shape[s] != null ? e.push(n.shape[s]) : e.push(t[s]); return e } return t }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ek(n, t, e, s) { const o = N(n, "x", "dropout"); if (v(o.dtype === "float32", () => `x has to be a floating point tensor since it's going to be scaled, but got a ${o.dtype} tensor instead.`), v(t >= 0 && t < 1, () => `rate must be a float in the range [0, 1), but got ${t}.`), t === 0) return n instanceof se ? o.clone() : o; const r = tk(o, e), i = 1 - t, a = dt($c(Q(Lc(r, 0, 1, "float32", s), i)), i); return E(o, a) } const nk = W({ dropout_: ek });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sk(n, t, e, s, o, r = "NHWC", i) { let a = n; n.rank === 3 && (a = D(n, [1, n.shape[0], n.shape[1], n.shape[2]])); let c = t; c.rank === 3 && (c = D(t, [1, t.shape[0], t.shape[1], t.shape[2]])), v(a.rank === 4, () => `Error in conv2dDerFilter: input must be rank 4, but got shape ${a.shape}.`), v(c.rank === 4, () => `Error in conv2dDerFilter: dy must be rank 4, but got shape ${c.shape}.`), v(e.length === 4, () => `Error in conv2dDerFilter: filterShape must be length 4, but got ${e}.`); const l = r === "NHWC" ? a.shape[3] : a.shape[1], u = r === "NHWC" ? c.shape[3] : c.shape[1]; v(l === e[2], () => `Error in conv2dDerFilter: depth of input ${l}) must match input depth in filter (${e[2]}.`), v(u === e[3], () => `Error in conv2dDerFilter: depth of dy (${u}) must match output depth for filter (${e[3]}).`), Fe("conv2dDerFilter", o, i); const d = { x: a, dy: c }, h = { strides: s, pad: o, dataFormat: r, dimRoundingMode: i, filterShape: e }; return L.runKernel(ru, d, h) } const Md = W({ conv2DBackpropFilter_: sk });/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Fd(n, t, e) { if (e == null || e === "linear") return n; if (e === "relu") return E(n, Ni(t)); throw new Error(`Cannot compute gradient for fused activation ${e}.`) } function Vd(n, t) { let e = t; const s = ce(n.shape, t.shape); return s.length > 0 && (e = ut(e, s)), D(e, n.shape) } function zd(n, t, e, s) { if (t === "linear") return n; if (t === "relu") return so(n); if (t === "elu") return Tc(n); if (t === "relu6") return Vm(n); if (t === "prelu") return wd(n, e); if (t === "leakyrelu") return md(n, s); if (t === "sigmoid") return Ao(n); throw new Error(`Unknown fused activation ${t}.`) } const Xd = (n, t) => !(n > 0) || t === "linear";/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ok({ x: n, filter: t, strides: e, pad: s, dataFormat: o = "NHWC", dilations: r = [1, 1], dimRoundingMode: i, bias: a, activation: c = "linear", preluActivationWeights: l, leakyreluAlpha: u }) { if (c = c || "linear", Xd(L.state.gradientDepth, c) === !1) { v(o === "NHWC", () => `Error in fused conv2d: got dataFormat of ${o} but only NHWC is currently supported for the case of gradient depth is 0 and the activation is not linear.`); let w = qs(n, t, e, s, o, r, i); return a != null && (w = Q(w, a)), zd(w, c, l, u) } const d = N(n, "x", "conv2d", "float32"), h = N(t, "filter", "conv2d", "float32"); let p = d, f = !1; d.rank === 3 && (f = !0, p = D(d, [1, d.shape[0], d.shape[1], d.shape[2]])), v(p.rank === 4, () => `Error in fused conv2d: input must be rank 4, but got rank ${p.rank}.`), v(h.rank === 4, () => `Error in fused conv2d: filter must be rank 4, but got rank ${h.rank}.`), Fe("fused conv2d", s, i); const m = o === "NHWC" ? p.shape[3] : p.shape[1]; v(h.shape[2] === m, () => `Error in conv2d: depth of input (${m}) must match input depth for filter ${h.shape[2]}.`), v(Te(e, r), () => `Error in conv2D: Either strides or dilations must be 1. Got strides ${e} and dilations '${r}'`); const g = ye(p.shape, h.shape, e, r, s, i); let b; a != null && (b = N(a, "bias", "fused conv2d"), [b] = qt(b, d), o === "NHWC" ? gt(g.outShape, b.shape) : (v(b.shape.length <= 1, () => `Error in fused conv2d: only supports scalar or 1-D Tensor bias for NCHW format but got the bias of rank-${b.shape.length}.`), v(b.shape.length === 0 || b.shape[0] === g.outChannels || b.shape[0] === 1, () => `Error in fused conv2d: bias shape (${b.shape}) is not compatible with the number of output channels (${g.outChannels})`))); let x; if (l != null) { const w = l.shape; if (v(w.length <= 1 || w.length === 3, () => `Error in fused conv2d: only supports scalar, 1-D Tensor or 3-D Tensor PReLU activation weights but got a tensor of rank-${w.length}.`), w.length === 1) v(w[0] === 1 || w[0] === g.outChannels, () => `Error in fused conv2d: PReLU activation weights (${w}) is not compatible with the number of output channels (${g.outChannels}).`); else if (w.length === 3) try { gt(w, g.outShape) } catch { const S = `Error in fused conv2d: PReLU activation weights (${w}) is not compatible with the output shape of the conv2d (${g.outShape}).`; throw Error(S) } x = N(l, "prelu weights", "fused conv2d") } const I = (w, k) => { v(o === "NHWC", () => `Error in gradient of fused conv2D: got dataFormat of ${o} but only NHWC is currently supported.`); const [S, T, R, G] = k, F = Fd(w, R, c); v(Js(r), () => `Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '${r}'`); const V = cd(T.shape, F, S, e, s), z = Md(T, F, S.shape, e, s), X = [V, z]; if (G != null) { const O = Vd(G, F); X.push(O) } return X }, y = { x: p, filter: h, bias: b, preluActivationWeights: x }, C = { strides: e, pad: s, dataFormat: o, dilations: r, dimRoundingMode: i, activation: c, leakyreluAlpha: u }; return a == null ? Zo((k, S, T) => { let R = L.runKernel(gc, y, C); return T([S, k, R]), f && (R = D(R, [R.shape[1], R.shape[2], R.shape[3]])), { value: R, gradFunc: I } })(p, h) : Zo((k, S, T, R) => { let G = L.runKernel(gc, y, C); return R([S, k, G, T]), f && (G = D(G, [G.shape[1], G.shape[2], G.shape[3]])), { value: G, gradFunc: I } })(p, h, b) } const rk = W({ fusedConv2d_: ok });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ik(n, t, e, s, o, r = [1, 1], i) { let a = n; n.rank === 3 && (a = D(n, [1, n.shape[0], n.shape[1], n.shape[2]])); let c = t; c.rank === 3 && (c = D(t, [1, t.shape[0], t.shape[1], t.shape[2]])); const l = { x: a, dy: c }, u = { strides: s, pad: o, dimRoundingMode: i, dilations: r, filterShape: e }; return L.runKernel(hu, l, u) } const ak = W({ depthwiseConv2dNativeBackpropFilter_: ik });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ck(n, t, e, s, o, r = [1, 1], i) { let a = t, c = !1; t.rank === 3 && (c = !0, a = D(t, [1, t.shape[0], t.shape[1], t.shape[2]])); const l = { dy: a, filter: e }, u = { strides: s, pad: o, dimRoundingMode: i, dilations: r, inputShape: n }, d = L.runKernel(pu, l, u); return c ? D(d, [d.shape[1], d.shape[2], d.shape[3]]) : d } const lk = W({ depthwiseConv2dNativeBackpropInput_: ck });/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function uk({ a: n, b: t, transposeA: e = !1, transposeB: s = !1, bias: o, activation: r = "linear", preluActivationWeights: i, leakyreluAlpha: a = .2 }) { if (Xd(L.state.gradientDepth, r) === !1) { let G = $t(n, t, e, s); return o != null && (G = Q(G, o)), zd(G, r, i, a) } let c = N(n, "a", "fused matMul"), l = N(t, "b", "fused matMul");[c, l] = qt(c, l); const u = e ? c.shape[c.rank - 2] : c.shape[c.rank - 1], d = s ? l.shape[l.rank - 1] : l.shape[l.rank - 2], h = e ? c.shape[c.rank - 1] : c.shape[c.rank - 2], p = s ? l.shape[l.rank - 2] : l.shape[l.rank - 1], f = c.shape.slice(0, -2), m = l.shape.slice(0, -2), g = Z(f), b = Z(m); v(u === d, () => `Error in fused matMul: inner shapes (${u}) and (${d}) of Tensors with shapes ${c.shape} and ${l.shape} and transposeA=${e} and transposeB=${s} must match.`); const I = gt(c.shape.slice(0, -2), l.shape.slice(0, -2)).concat([h, p]), y = e ? D(c, [g, u, h]) : D(c, [g, h, u]), C = s ? D(l, [b, p, d]) : D(l, [b, d, p]); let w; o != null && (w = N(o, "bias", "fused matMul"), [w] = qt(w, c), gt(I, w.shape)); let k; i != null && (k = N(i, "prelu weights", "fused matMul")); const S = (G, F) => { const [V, z, X, O] = F, B = Fd(D(G, X.shape), X, r); let K, H; if (!e && !s ? (K = $t(B, z, !1, !0), H = $t(V, B, !0, !1)) : !e && s ? (K = $t(B, z, !1, !1), H = $t(B, V, !0, !1)) : e && !s ? (K = $t(z, B, !1, !0), H = $t(V, B, !1, !1)) : (K = $t(z, B, !0, !0), H = $t(B, V, !0, !0)), o != null) { const U = Vd(O, B); return [K, H, U] } else return [K, H] }, T = { a: y, b: C, bias: w, preluActivationWeights: k }, R = { transposeA: e, transposeB: s, activation: r, leakyreluAlpha: a }; return o == null ? Zo((F, V, z) => { const X = L.runKernel(mc, T, R); return z([F, V, X]), { value: D(X, I), gradFunc: S } })(y, C) : Zo((F, V, z, X) => { const O = L.runKernel(mc, T, R); return X([F, V, O, z]), { value: D(O, I), gradFunc: S } })(y, C, w) } const Qm = W({ fusedMatMul_: uk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dk(n, t, e, s, o = "bilinear", r = 0) { const i = N(n, "image", "cropAndResize"), a = N(t, "boxes", "cropAndResize", "float32"), c = N(e, "boxInd", "cropAndResize", "int32"), l = a.shape[0]; v(i.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${i.rank}.`), v(a.rank === 2 && a.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${l},4] but had shape ${a.shape}.`), v(c.rank === 1 && c.shape[0] === l, () => `Error in cropAndResize: boxInd must be have size [${l}] but had shape ${a.shape}.`), v(s.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${s.length}.`), v(s[0] >= 1 && s[1] >= 1, () => `cropSize must be atleast [1,1], but was ${s}`), v(o === "bilinear" || o === "nearest", () => `method must be bilinear or nearest, but was ${o}`); const u = { image: i, boxes: a, boxInd: c }, d = { method: o, extrapolationValue: r, cropSize: s }; return L.runKernel(lu, u, d) } const hk = W({ cropAndResize_: dk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pk(n) { const t = N(n, "image", "flipLeftRight", "float32"); v(t.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${t.rank}.`); const e = { image: t }; return L.runKernel(yu, e, {}) } const fk = W({ flipLeftRight_: pk });/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mk(n) { const t = N(n, "image", "grayscaleToRGB"), e = t.rank - 1, s = t.shape[e]; v(t.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${t.rank}.`), v(s === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${s}.`); const o = new Array(t.rank); return o.fill(1, 0, e), o[e] = 3, Nn(t, o) } const gk = W({ grayscaleToRGB_: mk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bk(n, t, e = 0, s = .5) { const o = N(n, "image", "rotateWithOffset", "float32"); v(o.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${o.rank}.`); const r = { image: o }, i = { radians: t, fillValue: e, center: s }; return L.runKernel(zu, r, i) } const xk = W({ rotateWithOffset_: bk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Bo(n, t, e, s, o, r) { s == null && (s = .5), o == null && (o = Number.NEGATIVE_INFINITY), r == null && (r = 0); const i = n.shape[0]; return e = Math.min(e, i), v(0 <= s && s <= 1, () => `iouThreshold must be in [0, 1], but was '${s}'`), v(n.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${n.rank}'`), v(n.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${n.shape[1]}`), v(t.rank === 1, () => "scores must be a 1D tensor"), v(t.shape[0] === i, () => `scores has incompatible shape with boxes. Expected ${i}, but was ${t.shape[0]}`), v(0 <= r && r <= 1, () => `softNmsSigma must be in [0, 1], but was '${r}'`), { maxOutputSize: e, iouThreshold: s, scoreThreshold: o, softNmsSigma: r } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yk(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY) { const r = N(n, "boxes", "nonMaxSuppression", "float32"), i = N(t, "scores", "nonMaxSuppression", "float32"), a = Bo(r, i, e, s, o); e = a.maxOutputSize, s = a.iouThreshold, o = a.scoreThreshold; const c = { maxOutputSize: e, iouThreshold: s, scoreThreshold: o }; return L.runKernel(ku, { boxes: r, scores: i }, c) } const Ik = W({ nonMaxSuppression_: yk });/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ck(n, t, e) { const s = wk(n, t, e), o = s < 0 ? -(s + 1) : s; n.splice(o, 0, t) } function wk(n, t, e) { return Sk(n, t, e || vk) } function vk(n, t) { return n > t ? 1 : n < t ? -1 : 0 } function Sk(n, t, e) { let s = 0, o = n.length, r = 0, i = !1; for (; s < o;) { r = s + (o - s >>> 1); const a = e(t, n[r]); a > 0 ? s = r + 1 : (o = r, i = !a) } return i ? s : -s - 1 }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ad(n, t, e, s, o) { return Kd(n, t, e, s, o, 0) } function Od(n, t, e, s, o, r) { return Kd(n, t, e, s, o, 0, !1, r, !0) } function Pd(n, t, e, s, o, r) { return Kd(n, t, e, s, o, r, !0) } function Kd(n, t, e, s, o, r, i = !1, a = !1, c = !1) { const l = []; for (let g = 0; g < t.length; g++)t[g] > o && l.push({ score: t[g], boxIndex: g, suppressBeginIndex: 0 }); l.sort(Jm); const u = r > 0 ? -.5 / r : 0, d = [], h = []; for (; d.length < e && l.length > 0;) { const g = l.pop(), { score: b, boxIndex: x, suppressBeginIndex: I } = g; if (b < o) break; let y = !1; for (let C = d.length - 1; C >= I; --C) { const w = kk(n, x, d[C]); if (w >= s) { y = !0; break } if (g.score = g.score * Tk(s, u, w), g.score <= o) break } g.suppressBeginIndex = d.length, y || (g.score === b ? (d.push(x), h.push(g.score)) : g.score > o && Ck(l, g, Jm)) } const p = d.length, f = e - p; a && f > 0 && (d.push(...new Array(f).fill(0)), h.push(...new Array(f).fill(0))); const m = { selectedIndices: d }; return i && (m.selectedScores = h), c && (m.validOutputs = p), m } function kk(n, t, e) { const s = n.subarray(t * 4, t * 4 + 4), o = n.subarray(e * 4, e * 4 + 4), r = Math.min(s[0], s[2]), i = Math.min(s[1], s[3]), a = Math.max(s[0], s[2]), c = Math.max(s[1], s[3]), l = Math.min(o[0], o[2]), u = Math.min(o[1], o[3]), d = Math.max(o[0], o[2]), h = Math.max(o[1], o[3]), p = (a - r) * (c - i), f = (d - l) * (h - u); if (p <= 0 || f <= 0) return 0; const m = Math.max(r, l), g = Math.max(i, u), b = Math.min(a, d), x = Math.min(c, h), I = Math.max(b - m, 0) * Math.max(x - g, 0); return I / (p + f - I) } function Tk(n, t, e) { const s = Math.exp(t * e * e); return e <= n ? s : 0 } function Jm(n, t) { return n.score - t.score || n.score === t.score && t.boxIndex - n.boxIndex }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */async function Nk(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY) { const r = N(n, "boxes", "nonMaxSuppressionAsync"), i = N(t, "scores", "nonMaxSuppressionAsync"), a = Bo(r, i, e, s, o); e = a.maxOutputSize, s = a.iouThreshold, o = a.scoreThreshold; const c = await Promise.all([r.data(), i.data()]), l = c[0], u = c[1], { selectedIndices: d } = Ad(l, u, e, s, o); return r !== n && r.dispose(), i !== t && i.dispose(), on(d, "int32") } const Rk = Nk;/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $k(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY, r = 0) { const i = N(n, "boxes", "nonMaxSuppression"), a = N(t, "scores", "nonMaxSuppression"), c = Bo(i, a, e, s, o, r); e = c.maxOutputSize, s = c.iouThreshold, o = c.scoreThreshold, r = c.softNmsSigma; const l = { boxes: i, scores: a }, u = { maxOutputSize: e, iouThreshold: s, scoreThreshold: o, softNmsSigma: r }, d = L.runKernel(Nu, l, u); return { selectedIndices: d[0], selectedScores: d[1] } } const Gk = W({ nonMaxSuppressionWithScore_: $k });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */async function Lk(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY, r = 0) { const i = N(n, "boxes", "nonMaxSuppressionAsync"), a = N(t, "scores", "nonMaxSuppressionAsync"), c = Bo(i, a, e, s, o, r); e = c.maxOutputSize, s = c.iouThreshold, o = c.scoreThreshold, r = c.softNmsSigma; const l = await Promise.all([i.data(), a.data()]), u = l[0], d = l[1], { selectedIndices: h, selectedScores: p } = Pd(u, d, e, s, o, r); return i !== n && i.dispose(), a !== t && a.dispose(), { selectedIndices: on(h, "int32"), selectedScores: on(p) } } const Ek = Lk;/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Dk(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY, r = !1) { const i = N(n, "boxes", "nonMaxSuppression"), a = N(t, "scores", "nonMaxSuppression"), c = Bo(i, a, e, s, o, null), l = c.maxOutputSize, u = c.iouThreshold, d = c.scoreThreshold, h = { boxes: i, scores: a }, p = { maxOutputSize: l, iouThreshold: u, scoreThreshold: d, padToMaxOutputSize: r }, f = L.runKernel(Tu, h, p); return { selectedIndices: f[0], validOutputs: f[1] } } const Wk = W({ nonMaxSuppressionPadded_: Dk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */async function Mk(n, t, e, s = .5, o = Number.NEGATIVE_INFINITY, r = !1) { const i = N(n, "boxes", "nonMaxSuppressionAsync"), a = N(t, "scores", "nonMaxSuppressionAsync"), c = Bo(i, a, e, s, o, null), l = c.maxOutputSize, u = c.iouThreshold, d = c.scoreThreshold, [h, p] = await Promise.all([i.data(), a.data()]), { selectedIndices: f, validOutputs: m } = Od(h, p, l, u, d, r); return i !== n && i.dispose(), a !== t && a.dispose(), { selectedIndices: on(f, "int32"), validOutputs: Gt(m, "int32") } } const Fk = Mk;/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Vk(n, t, e = !1, s = !1) { const o = N(n, "images", "resizeBilinear"); v(o.rank === 3 || o.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${o.rank}.`), v(t.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${t}.`), v(s === !1 || e === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false."); let r = o, i = !1; o.rank === 3 && (i = !0, r = D(o, [1, o.shape[0], o.shape[1], o.shape[2]])); const a = { images: r }, c = { alignCorners: e, halfPixelCenters: s, size: t }, l = L.runKernel(oc, a, c); return i ? D(l, [l.shape[1], l.shape[2], l.shape[3]]) : l } const jm = W({ resizeBilinear_: Vk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function zk(n, t, e = !1, s = !1) { const o = N(n, "images", "resizeNearestNeighbor"); v(o.rank === 3 || o.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${o.rank}.`), v(t.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${t}.`), v(o.dtype === "float32" || o.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), v(s === !1 || e === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false."); let r = o, i = !1; o.rank === 3 && (i = !0, r = D(o, [1, o.shape[0], o.shape[1], o.shape[2]])); const a = { images: r }, c = { alignCorners: e, halfPixelCenters: s, size: t }, l = L.runKernel(sc, a, c); return i ? D(l, [l.shape[1], l.shape[2], l.shape[3]]) : l } const qm = W({ resizeNearestNeighbor_: zk });/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Xk(n, t = "binary", e = !1, s = .5) { const o = N(n, "image", "threshold"), r = .2989, i = .587, a = .114, c = o.shape[0] * o.shape[1]; let l = E(on([s]), 255), u, d, h, p; if (v(o.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${o.rank}.`), v(o.shape[2] === 3 || o.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${o.shape[2]}.`), v(o.dtype === "int32" || o.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${o.dtype}.`), v(t === "otsu" || t === "binary", () => `Method must be binary or otsu, but was ${t}`), o.shape[2] === 3) { [u, d, h] = sn(o, [1, 1, 1], -1); const g = E(u, r), b = E(d, i), x = E(h, a); p = Q(Q(g, b), x) } else p = n; if (t === "otsu") { const g = Aw(ot(zm(p), "int32"), qe([]), 256); l = Ak(g, c) } const f = e ? Ko(p, l) : nn(p, l); return ot(E(f, 255), "int32") } function Ak(n, t) { let e = on([-1]), s = on([0]), o = on([0]), r, i, a, c, l, u; for (let d = 0; d < n.size - 1; d++) { r = Vt(n, 0, d + 1), i = Vt(n, d + 1), l = dt(ut(r), t), u = dt(ut(i), t); const h = ut(E(r, ki(0, r.size))); a = dt(h, ut(r)); const p = kc(i.shape, r.size), f = Q(ki(0, i.size), p), m = E(i, f); c = dt(ut(m), ut(i)); const g = ft(a, c), b = ft(a, c), x = E(l, u); o = E(E(x, g), b); const I = nn(o, s); s = Be(I, o, s), e = Be(I, on([d]), e) } return e } const Ok = W({ threshold_: Xk });/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Pk(n, t, e = "nearest", s = "constant", o = 0, r) { const i = N(n, "image", "transform", "float32"), a = N(t, "transforms", "transform", "float32"); v(i.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${i.rank}.`), v(a.rank === 2 && (a.shape[0] === i.shape[0] || a.shape[0] === 1) && a.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), v(r == null || r.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${r}.`); const c = { image: i, transforms: a }, l = { interpolation: e, fillMode: s, fillValue: o, outputShape: r }; return L.runKernel(Mu, c, l) } const Kk = W({ transform_: Pk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Zk(n, t, e) { v(t % 1 === 0, () => `bandPart(): numLower must be an integer, got ${t}.`), v(e % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${e}.`); const s = N(n, "a", "bandPart"); v(s.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${s.rank}.`); const o = s.shape, [r, i] = s.shape.slice(-2); if (!(t <= r)) throw new Error(`bandPart(): numLower (${t}) must not be greater than the number of rows (${r}).`); if (!(e <= i)) throw new Error(`bandPart(): numUpper (${e}) must not be greater than the number of columns (${i}).`); t < 0 && (t = r), e < 0 && (e = i); const a = D(ki(0, r, 1, "int32"), [-1, 1]), c = ki(0, i, 1, "int32"), l = ft(a, c), u = ss(Ko(l, Gt(+t, "int32")), to(l, Gt(-e, "int32"))), d = me([r, i], s.dtype); return D(os(ro(D(s, [-1, r, i])).map(h => Be(u, h, d))), o) } const Bk = W({ bandPart_: Zk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Hk(n) { let t; if (Array.isArray(n)) { t = !1, v(n != null && n.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty"); const o = n[0].shape[0]; for (let r = 1; r < n.length; ++r)v(n[r].shape[0] === o, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${n[r].shape[0]} vs. ${o})`) } else t = !0, n = sn(n, n.shape[0], 0).map(o => Ti(o, [0])); v(n.length <= n[0].shape[0], () => `Gram-Schmidt: Number of vectors (${n.length}) exceeds number of dimensions (${n[0].shape[0]}).`); const e = [], s = n; for (let o = 0; o < n.length; ++o)e.push(L.tidy(() => { let r = s[o]; if (o > 0) for (let i = 0; i < o; ++i) { const a = E(ut(E(e[i], r)), e[i]); r = ft(r, a) } return dt(r, Rc(r, "euclidean")) })); return t ? os(e, 0) : e } const _k = W({ gramSchmidt_: Hk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Uk(n, t = !1) { if (v(n.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${n.rank}`), n.rank === 2) return tg(n, t); { const e = n.shape.slice(0, n.shape.length - 2).reduce((c, l) => c * l), s = ro(D(n, [e, n.shape[n.shape.length - 2], n.shape[n.shape.length - 1]]), 0), o = [], r = []; s.forEach(c => { const [l, u] = tg(c, t); o.push(l), r.push(u) }); const i = D(os(o, 0), n.shape), a = D(os(r, 0), n.shape); return [i, a] } } function tg(n, t = !1) { return L.tidy(() => { v(n.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${n.shape.length}D Tensor.`); const e = n.shape[0], s = n.shape[1]; let o = $m(e), r = Qs(n); const i = Wd([[1]], [1, 1]); let a = Qs(i); const c = e >= s ? s : e; for (let l = 0; l < c; ++l) { const u = r, d = a, h = o;[a, r, o] = L.tidy(() => { const p = Vt(r, [l, l], [e - l, 1]), f = Rc(p), m = Vt(r, [l, l], [1, 1]), g = Be(nn(m, 0), Wd([[-1]]), Wd([[1]])), b = ft(m, E(g, f)), x = dt(p, b); x.shape[0] === 1 ? a = Qs(i) : a = Ve([i, Vt(x, [1, 0], [x.shape[0] - 1, x.shape[1]])], 0); const I = re(dt($t(g, b), f)), y = Vt(r, [l, 0], [e - l, s]), C = E(I, a), w = St(a); if (l === 0) r = ft(y, $t(C, $t(w, y))); else { const T = ft(y, $t(C, $t(w, y))); r = Ve([Vt(r, [0, 0], [l, s]), T], 0) } const k = St(C), S = Vt(o, [0, l], [e, o.shape[1] - l]); if (l === 0) o = ft(S, $t($t(S, a), k)); else { const T = ft(S, $t($t(S, a), k)); o = Ve([Vt(o, [0, 0], [e, l]), T], 1) } return [a, r, o] }), wt([u, d, h]) } return !t && e > s && (o = Vt(o, [0, 0], [e, s]), r = Vt(r, [0, 0], [s, s])), [o, r] }) } const Yk = W({ qr_: Uk });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const io = { flipLeftRight: fk, grayscaleToRGB: gk, resizeNearestNeighbor: qm, resizeBilinear: jm, rotateWithOffset: xk, cropAndResize: hk, nonMaxSuppression: Ik, nonMaxSuppressionAsync: Rk, nonMaxSuppressionWithScore: Gk, nonMaxSuppressionWithScoreAsync: Ek, nonMaxSuppressionPadded: Wk, nonMaxSuppressionPaddedAsync: Fk, threshold: Ok, transform: Kk }, Qk = { bandPart: Bk, gramSchmidt: _k, qr: Yk };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Ho { getClassName() { return this.constructor.className } static fromConfig(t, e) { return new t(e) } } class fn { constructor() { this.classNameMap = {} } static getMap() { return fn.instance == null && (fn.instance = new fn), fn.instance } static register(t) { fn.getMap().classNameMap[t.className] = [t, t.fromConfig] } } function _(n) { v(n.className != null, () => "Class being registered does not have the static className property defined."), v(typeof n.className == "string", () => "className is required to be a string, but got type " + typeof n.className), v(n.className.length > 0, () => "Class being registered has an empty-string as its className, which is disallowed."), fn.register(n) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Cs extends Ho { minimize(t, e = !1, s) { const { value: o, grads: r } = this.computeGradients(t, s); if (s != null) { const i = s.map(a => ({ name: a.name, tensor: r[a.name] })); this.applyGradients(i) } else this.applyGradients(r); return wt(r), e ? o : (o.dispose(), null) } get iterations() { return this.iterations_ == null && (this.iterations_ = 0), this.iterations_ } incrementIterations() { this.iterations_ = this.iterations + 1 } computeGradients(t, e) { return av(t, e) } dispose() { this.iterations_ != null && wt(this.iterations_) } async saveIterations() { return this.iterations_ == null && (this.iterations_ = 0), { name: "iter", tensor: Gt(this.iterations_, "int32") } } async getWeights() { throw new Error("getWeights() is not implemented for this optimizer yet.") } async setWeights(t) { throw new Error(`setWeights() is not implemented for this optimizer class ${this.getClassName()}`) } async extractIterations(t) { return this.iterations_ = (await t[0].tensor.data())[0], t.slice(1) } } Object.defineProperty(Cs, Symbol.hasInstance, { value: n => n.minimize != null && n.computeGradients != null && n.applyGradients != null });/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class eg extends Cs { constructor(t, e, s = null) { super(), this.learningRate = t, this.rho = e, this.epsilon = s, this.accumulatedGrads = [], this.accumulatedUpdates = [], s == null && (this.epsilon = L.backend.epsilon()) } static get className() { return "Adadelta" } applyGradients(t) { (Array.isArray(t) ? t.map(s => s.name) : Object.keys(t)).forEach((s, o) => { const r = L.registeredVariables[s], i = !1; this.accumulatedGrads[o] == null && (this.accumulatedGrads[o] = { originalName: `${s}/accum_grad`, variable: M(() => kt(r).variable(i)) }), this.accumulatedUpdates[o] == null && (this.accumulatedUpdates[o] = { originalName: `${s}/accum_var`, variable: M(() => kt(r).variable(i)) }); const a = Array.isArray(t) ? t[o].tensor : t[s]; if (a == null) return; const c = this.accumulatedGrads[o].variable, l = this.accumulatedUpdates[o].variable; M(() => { const u = Q(E(c, this.rho), E(Zt(a), 1 - this.rho)), d = E(dt(Ge(Q(l, this.epsilon)), Ge(Q(c, this.epsilon))), a), h = Q(E(l, this.rho), E(Zt(d), 1 - this.rho)); c.assign(u), l.assign(h); const p = Q(E(d, -this.learningRate), r); r.assign(p) }) }), this.incrementIterations() } dispose() { this.accumulatedUpdates != null && (wt(this.accumulatedGrads.map(t => t.variable)), wt(this.accumulatedUpdates.map(t => t.variable))) } async getWeights() { const t = [...this.accumulatedGrads, ...this.accumulatedUpdates]; return [await this.saveIterations()].concat(t.map(e => ({ name: e.originalName, tensor: e.variable }))) } async setWeights(t) { t = await this.extractIterations(t); const e = t.length / 2, s = !1; this.accumulatedGrads = t.slice(0, e).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })), this.accumulatedUpdates = t.slice(e, e * 2).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })) } getConfig() { return { learningRate: this.learningRate, rho: this.rho, epsilon: this.epsilon } } static fromConfig(t, e) { return new t(e.learningRate, e.rho, e.epsilon) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class ng extends Cs { constructor(t, e = .1) { super(), this.learningRate = t, this.initialAccumulatorValue = e, this.accumulatedGrads = [] } static get className() { return "Adagrad" } applyGradients(t) { (Array.isArray(t) ? t.map(s => s.name) : Object.keys(t)).forEach((s, o) => { const r = L.registeredVariables[s]; this.accumulatedGrads[o] == null && (this.accumulatedGrads[o] = { originalName: `${s}/accumulator`, variable: M(() => kc(r.shape, this.initialAccumulatorValue).variable(!1)) }); const i = Array.isArray(t) ? t[o].tensor : t[s]; if (i == null) return; const a = this.accumulatedGrads[o].variable; M(() => { const c = Q(a, Zt(i)); a.assign(c); const l = Q(E(dt(i, Ge(Q(c, L.backend.epsilon()))), -this.learningRate), r); r.assign(l) }) }), this.incrementIterations() } dispose() { this.accumulatedGrads != null && wt(this.accumulatedGrads.map(t => t.variable)) } async getWeights() { return [await this.saveIterations()].concat(this.accumulatedGrads.map(t => ({ name: t.originalName, tensor: t.variable }))) } async setWeights(t) { t = await this.extractIterations(t); const e = !1; this.accumulatedGrads = t.map(s => ({ originalName: s.name, variable: s.tensor.variable(e) })) } getConfig() { return { learningRate: this.learningRate, initialAccumulatorValue: this.initialAccumulatorValue } } static fromConfig(t, e) { return new t(e.learningRate, e.initialAccumulatorValue) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class sg extends Cs { constructor(t, e, s, o = null) { super(), this.learningRate = t, this.beta1 = e, this.beta2 = s, this.epsilon = o, this.accumulatedFirstMoment = [], this.accumulatedSecondMoment = [], M(() => { this.accBeta1 = Gt(e).variable(), this.accBeta2 = Gt(s).variable() }), o == null && (this.epsilon = L.backend.epsilon()) } static get className() { return "Adam" } applyGradients(t) { const e = Array.isArray(t) ? t.map(s => s.name) : Object.keys(t); M(() => { const s = ft(1, this.accBeta1), o = ft(1, this.accBeta2); e.forEach((r, i) => { const a = L.registeredVariables[r], c = !1; this.accumulatedFirstMoment[i] == null && (this.accumulatedFirstMoment[i] = { originalName: `${r}/m`, variable: M(() => kt(a).variable(c)) }), this.accumulatedSecondMoment[i] == null && (this.accumulatedSecondMoment[i] = { originalName: `${r}/v`, variable: M(() => kt(a).variable(c)) }); const l = Array.isArray(t) ? t[i].tensor : t[r]; if (l == null) return; const u = this.accumulatedFirstMoment[i].variable, d = this.accumulatedSecondMoment[i].variable, h = Q(E(u, this.beta1), E(l, 1 - this.beta1)), p = Q(E(d, this.beta2), E(Zt(l), 1 - this.beta2)), f = dt(h, s), m = dt(p, o); u.assign(h), d.assign(p); const g = Q(E(dt(f, Q(Ge(m), this.epsilon)), -this.learningRate), a); a.assign(g) }), this.accBeta1.assign(E(this.accBeta1, this.beta1)), this.accBeta2.assign(E(this.accBeta2, this.beta2)) }), this.incrementIterations() } dispose() { this.accBeta1.dispose(), this.accBeta2.dispose(), this.accumulatedFirstMoment != null && wt(this.accumulatedFirstMoment.map(t => t.variable)), this.accumulatedSecondMoment != null && wt(this.accumulatedSecondMoment.map(t => t.variable)) } async getWeights() { const t = [...this.accumulatedFirstMoment, ...this.accumulatedSecondMoment]; return [await this.saveIterations()].concat(t.map(e => ({ name: e.originalName, tensor: e.variable }))) } async setWeights(t) { t = await this.extractIterations(t), M(() => { this.accBeta1.assign(Po(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Po(this.beta2, this.iterations_ + 1)) }); const e = t.length / 2, s = !1; this.accumulatedFirstMoment = t.slice(0, e).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })), this.accumulatedSecondMoment = t.slice(e, e * 2).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })) } getConfig() { return { learningRate: this.learningRate, beta1: this.beta1, beta2: this.beta2, epsilon: this.epsilon } } static fromConfig(t, e) { return new t(e.learningRate, e.beta1, e.beta2, e.epsilon) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class og extends Cs { constructor(t, e, s, o = null, r = 0) { super(), this.learningRate = t, this.beta1 = e, this.beta2 = s, this.epsilon = o, this.decay = r, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], M(() => { this.iteration = Gt(0).variable(), this.accBeta1 = Gt(e).variable() }), o == null && (this.epsilon = L.backend.epsilon()) } static get className() { return "Adamax" } applyGradients(t) { const e = Array.isArray(t) ? t.map(s => s.name) : Object.keys(t); M(() => { const s = ft(1, this.accBeta1), o = dt(-this.learningRate, Q(E(this.iteration, this.decay), 1)); e.forEach((r, i) => { const a = L.registeredVariables[r], c = !1; this.accumulatedFirstMoment[i] == null && (this.accumulatedFirstMoment[i] = { originalName: `${r}/m`, variable: kt(a).variable(c) }), this.accumulatedWeightedInfNorm[i] == null && (this.accumulatedWeightedInfNorm[i] = { originalName: `${r}/v`, variable: kt(a).variable(c) }); const l = Array.isArray(t) ? t[i].tensor : t[r]; if (l == null) return; const u = this.accumulatedFirstMoment[i].variable, d = this.accumulatedWeightedInfNorm[i].variable, h = Q(E(u, this.beta1), E(l, 1 - this.beta1)), p = E(d, this.beta2), f = $e(l), m = Is(p, f); u.assign(h), d.assign(m); const g = Q(E(dt(o, s), dt(h, Q(m, this.epsilon))), a); a.assign(g) }), this.iteration.assign(Q(this.iteration, 1)), this.accBeta1.assign(E(this.accBeta1, this.beta1)) }), this.incrementIterations() } dispose() { this.accBeta1.dispose(), this.iteration.dispose(), this.accumulatedFirstMoment != null && wt(this.accumulatedFirstMoment.map(t => t.variable)), this.accumulatedWeightedInfNorm != null && wt(this.accumulatedWeightedInfNorm.map(t => t.variable)) } async getWeights() { throw new Error("getWeights() is not implemented for Adamax yet.") } async setWeights(t) { throw new Error("setWeights() is not implemented for Adamax yet.") } getConfig() { return { learningRate: this.learningRate, beta1: this.beta1, beta2: this.beta2, epsilon: this.epsilon, decay: this.decay } } static fromConfig(t, e) { return new t(e.learningRate, e.beta1, e.beta2, e.epsilon, e.decay) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Zd extends Cs { constructor(t) { super(), this.learningRate = t, this.setLearningRate(t) } static get className() { return "SGD" } applyGradients(t) { (Array.isArray(t) ? t.map(s => s.name) : Object.keys(t)).forEach((s, o) => { const r = Array.isArray(t) ? t[o].tensor : t[s]; if (r == null) return; const i = L.registeredVariables[s]; M(() => { const a = Q(E(this.c, r), i); i.assign(a) }) }), this.incrementIterations() } setLearningRate(t) { this.learningRate = t, this.c != null && this.c.dispose(), this.c = tn(Gt(-t)) } dispose() { this.c.dispose() } async getWeights() { return [await this.saveIterations()] } async setWeights(t) { if (t = await this.extractIterations(t), t.length !== 0) throw new Error("SGD optimizer does not have settable weights.") } getConfig() { return { learningRate: this.learningRate } } static fromConfig(t, e) { return new t(e.learningRate) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class rg extends Zd { constructor(t, e, s = !1) { super(t), this.learningRate = t, this.momentum = e, this.useNesterov = s, this.accumulations = [], this.m = Gt(this.momentum) } static get className() { return "Momentum" } applyGradients(t) { (Array.isArray(t) ? t.map(s => s.name) : Object.keys(t)).forEach((s, o) => { const r = L.registeredVariables[s]; this.accumulations[o] == null && (this.accumulations[o] = { originalName: `${s}/momentum`, variable: M(() => kt(r).variable(!1)) }); const i = this.accumulations[o].variable, a = Array.isArray(t) ? t[o].tensor : t[s]; a != null && M(() => { let c; const l = Q(E(this.m, i), a); this.useNesterov ? c = Q(E(this.c, Q(a, E(l, this.m))), r) : c = Q(E(this.c, l), r), i.assign(l), r.assign(c) }) }), this.incrementIterations() } dispose() { this.m.dispose(), this.accumulations != null && wt(this.accumulations.map(t => t.variable)) } setMomentum(t) { this.momentum = t } async getWeights() { return [await this.saveIterations()].concat(this.accumulations.map(t => ({ name: t.originalName, tensor: t.variable }))) } async setWeights(t) { t = await this.extractIterations(t); const e = !1; this.accumulations = t.map(s => ({ originalName: s.name, variable: s.tensor.variable(e) })) } getConfig() { return { learningRate: this.learningRate, momentum: this.momentum, useNesterov: this.useNesterov } } static fromConfig(t, e) { return new t(e.learningRate, e.momentum, e.useNesterov) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class ig extends Cs { constructor(t, e = .9, s = 0, o = null, r = !1) { if (super(), this.learningRate = t, this.decay = e, this.momentum = s, this.epsilon = o, this.accumulatedMeanSquares = [], this.accumulatedMoments = [], this.accumulatedMeanGrads = [], this.centered = r, o == null && (this.epsilon = L.backend.epsilon()), t == null) throw new Error("learningRate for RMSPropOptimizer must be defined.") } static get className() { return "RMSProp" } applyGradients(t) { (Array.isArray(t) ? t.map(s => s.name) : Object.keys(t)).forEach((s, o) => { const r = L.registeredVariables[s], i = !1; this.accumulatedMeanSquares[o] == null && (this.accumulatedMeanSquares[o] = { originalName: `${s}/rms`, variable: M(() => kt(r).variable(i)) }), this.accumulatedMoments[o] == null && (this.accumulatedMoments[o] = { originalName: `${s}/momentum`, variable: M(() => kt(r).variable(i)) }), this.accumulatedMeanGrads[o] == null && this.centered && (this.accumulatedMeanGrads[o] = { originalName: `${s}/mg`, variable: M(() => kt(r).variable(i)) }); const a = Array.isArray(t) ? t[o].tensor : t[s]; if (a == null) return; const c = this.accumulatedMeanSquares[o].variable, l = this.accumulatedMoments[o].variable; M(() => { const u = Q(E(c, this.decay), E(Zt(a), 1 - this.decay)); if (this.centered) { const d = this.accumulatedMeanGrads[o].variable, h = Q(E(d, this.decay), E(a, 1 - this.decay)), p = dt(E(a, this.learningRate), Ge(ft(u, Q(Zt(h), this.epsilon)))), f = Q(E(l, this.momentum), p); c.assign(u), d.assign(h), l.assign(f); const m = ft(r, f); r.assign(m) } else { const d = Q(E(c, this.decay), E(Zt(a), 1 - this.decay)), h = Q(E(l, this.momentum), dt(E(a, this.learningRate), Ge(Q(d, this.epsilon)))); c.assign(d), l.assign(h); const p = ft(r, h); r.assign(p) } }) }), this.incrementIterations() } dispose() { this.accumulatedMeanSquares != null && wt(this.accumulatedMeanSquares.map(t => t.variable)), this.accumulatedMeanGrads != null && this.centered && wt(this.accumulatedMeanGrads.map(t => t.variable)), this.accumulatedMoments != null && wt(this.accumulatedMoments.map(t => t.variable)) } async getWeights() { const t = [...this.accumulatedMeanSquares, ...this.accumulatedMoments]; return this.centered && t.push(...this.accumulatedMeanGrads), [await this.saveIterations()].concat(t.map(e => ({ name: e.originalName, tensor: e.variable }))) } async setWeights(t) { t = await this.extractIterations(t); const e = this.centered ? t.length / 3 : t.length / 2, s = !1; this.accumulatedMeanSquares = t.slice(0, e).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })), this.accumulatedMoments = t.slice(e, e * 2).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) })), this.centered && (this.accumulatedMeanGrads = t.slice(e * 2, e * 3).map(o => ({ originalName: o.name, variable: o.tensor.variable(s) }))) } getConfig() { return { learningRate: this.learningRate, decay: this.decay, momentum: this.momentum, epsilon: this.epsilon, centered: this.centered } } static fromConfig(t, e) { return new t(e.learningRate, e.decay, e.momentum, e.epsilon, e.centered) } }/**
 * @license
 * Copyright 2022 Google LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Jk = [eg, ng, sg, og, rg, ig, Zd]; function jk() { for (const n of Jk) _(n) }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */let ao; function qk(n, t = 3) { if (t > 4) throw new Error("Cannot construct Tensor with more than 4 channels from pixels."); if (n == null) throw new Error("pixels passed to tf.browser.fromPixels() can not be null"); let e = !1, s = !1, o = !1, r = !1, i = !1, a = !1; if (n.data instanceof Uint8Array) e = !0; else if (typeof ImageData < "u" && n instanceof ImageData) s = !0; else if (typeof HTMLVideoElement < "u" && n instanceof HTMLVideoElement) o = !0; else if (typeof HTMLImageElement < "u" && n instanceof HTMLImageElement) r = !0; else if (n.getContext != null) i = !0; else if (typeof ImageBitmap < "u" && n instanceof ImageBitmap) a = !0; else throw new Error(`pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was ${n.constructor.name}`); if (Au(Vu, L.backendName) != null) { const f = { pixels: n }, m = { numChannels: t }; return L.runKernel(Vu, f, m) } const [l, u] = o ? [n.videoWidth, n.videoHeight] : [n.width, n.height]; let d; if (i) d = n.getContext("2d").getImageData(0, 0, l, u).data; else if (s || e) d = n.data; else if (r || o || a) { if (ao == null) if (typeof document > "u") if (typeof OffscreenCanvas < "u" && typeof OffscreenCanvasRenderingContext2D < "u") ao = new OffscreenCanvas(1, 1).getContext("2d"); else throw new Error("Cannot parse input in current context. Reason: OffscreenCanvas Context2D rendering is not supported."); else ao = document.createElement("canvas").getContext("2d", { willReadFrequently: !0 }); ao.canvas.width = l, ao.canvas.height = u, ao.drawImage(n, 0, 0, l, u), d = ao.getImageData(0, 0, l, u).data } let h; if (t === 4) h = new Int32Array(d); else { const f = l * u; h = new Int32Array(f * t); for (let m = 0; m < f; m++)for (let g = 0; g < t; ++g)h[m * t + g] = d[m * 4 + g] } return KS(h, [u, l, t], "int32") } const tT = W({ fromPixels_: qk }); function Bd(n, t) { const e = n.shape.length, s = t.shape.length; if (e < 1) throw new Error(`tf.gatherND() expects the input to be rank 1 or higher, but the rank was ${e}.`); if (s < 1) throw new Error(`tf.gatherND() expects the indices to be rank 1 or higher, but the rank was ${s}.`); if (t.dtype !== "int32") throw new Error(`tf.gatherND() expects the indices to be int32 type, but the dtype was ${t.dtype}.`); if (t.shape[s - 1] > e) throw new Error(`index innermost dimension length must be <= tensor rank; saw: ${t.shape[s - 1]} vs. ${e}`); if (Z(n.shape) === 0) throw new Error(`Requested more than 0 entries, but input is empty. Input shape: ${n.shape}.`); const o = t.shape, r = o[o.length - 1]; let i = 1; for (let d = 0; d < o.length - 1; ++d)i *= o[d]; const a = n.shape, c = o.slice(); c.pop(); let l = 1; for (let d = r; d < e; ++d)l *= a[d], c.push(a[d]); const u = [...ct(n.shape).map(d => d / l), 1].slice(0, r); return [c, i, l, u] }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Hd = -2, eT = -1; function _d(n, t, e) { const s = n.shape.length; v(s === t.length, () => `Error in slice${s}D: Length of begin ${t} must match the rank of the array (${s}).`), v(s === e.length, () => `Error in slice${s}D: Length of size ${e} must match the rank of the array (${s}).`); for (let o = 0; o < s; ++o)v(t[o] + e[o] <= n.shape[o], () => `Error in slice${s}D: begin[${o}] + size[${o}] (${t[o] + e[o]}) would overflow input.shape[${o}] (${n.shape[o]})`) } function nT(n) { const t = []; let e = 0; for (; n > 0;)n & 1 && t.push(e), n /= 2, e++; return t } function Ud(n, t, e) { const s = []; for (let o = 0; o < n.length; o++)s[o] = Math.ceil((t[o] - n[o]) / e[o]); return s } function ag(n, t, e, s) { const o = [...n]; for (let r = o.length; r < s.length; r++)o.push(1); for (let r = 0; r < e; r++)r === 0 ? o[t] = 1 : (o.splice(t, 0, 1), o.pop()); return o } function cg(n, t, e) { return e <= n ? e : e - (t - 1) } function lg(n, t) { const e = []; for (let s = 0; s < n; s++)e.push(t + s); return e } function sT(n, t, e, s, o, r, i, a, c) { const l = n.length; let u = new Array(l), d = new Array(l), h = new Array(l); if (t.length && e > 0) { const p = t[0], f = e + 1; u = ug(i, p, f, s, n), d = dg(a, p, f, o, n), h = ag(r, p, f, n) } else for (let p = 0; p < l; p++)u[p] = pg(i, s, r, n, p, c), d[p] = fg(a, o, r, n, p, c), h[p] = hg(r, p, c); return { begin: u, end: d, strides: h } } function ug(n, t, e, s, o) { const r = [...o], i = lg(e, t); for (let a = 0; a < r.length; a++)if (i.indexOf(a) > -1) r[a] = 0; else { const c = cg(t, e, a); let l = s[c]; n & 1 << c && (l = 0), r[a] = l } return r } function dg(n, t, e, s, o) { const r = [...o], i = lg(e, t); for (let a = 0; a < r.length; a++)if (i.indexOf(a) > -1) r[a] = Number.MAX_SAFE_INTEGER; else { const c = cg(t, e, a); let l = s[c]; n & 1 << c && (l = Number.MAX_SAFE_INTEGER), r[a] = l } for (let a = 0; a < r.length; a++) { const c = o[a]; r[a] < 0 && (r[a] += c), r[a] = Xs(0, r[a], o[a]) } return r } function hg(n, t, e) { let s = n[t]; return (e & 1 << t || s == null) && (s = 1), s } function pg(n, t, e, s, o, r) { let i = t[o]; const a = e[o] || 1; (n & 1 << o || r & 1 << o || i == null) && (a > 0 ? i = Number.MIN_SAFE_INTEGER : i = Number.MAX_SAFE_INTEGER); const c = s[o]; return i < 0 && (i += c), i = Xs(0, i, c - 1), i } function fg(n, t, e, s, o, r) { let i = t[o]; const a = e[o] || 1; (n & 1 << o || r & 1 << o || i == null) && (a > 0 ? i = Number.MAX_SAFE_INTEGER : i = Number.MIN_SAFE_INTEGER); const c = s[o]; return i < 0 && (i += c), a > 0 ? i = Xs(0, i, c) : i = Xs(-1, i, c - 1), i } function Yd(n, t, e) { let s = e.length; for (let o = 0; o < e.length; o++)if (e[o] > 1) { s = o; break } for (let o = s + 1; o < e.length; o++)if (t[o] > 0 || e[o] !== n[o]) return !1; return !0 } function Qd(n, t) { let e = n.length > 0 ? n[n.length - 1] : 1; for (let s = 0; s < n.length - 1; s++)e += n[s] * t[s]; return e } function Wc(n, t, e) { let s; const o = n.shape.length; typeof t == "number" ? s = [t, ...new Array(o - 1).fill(0)] : t.length < o ? s = t.concat(new Array(o - t.length).fill(0)) : s = t.slice(), s.forEach(i => { v(i !== -1, () => "slice() does not support negative begin indexing.") }); let r; return e == null ? r = new Array(o).fill(-1) : typeof e == "number" ? r = [e, ...new Array(o - 1).fill(-1)] : e.length < o ? r = e.concat(new Array(o - e.length).fill(-1)) : r = e, r = r.map((i, a) => i >= 0 ? i : (v(i === -1, () => `Negative size values should be exactly -1 but got ${i} for the slice() size at index ${a}.`), n.shape[a] - s[a])), [s, r] } function Jd(n, t, e, s, o, r, i, a, c) { let l; if (s == null ? (l = new Array(t.length), l.fill(1)) : l = s, i != null && i & i - 1) throw new Error("Multiple ellipses in slice is not allowed."); let u = !1; const d = { dims: l.length, numAddAxisAfterEllipsis: 0, begin: t.slice(), end: e.slice(), strides: l.slice(), beginMask: o, endMask: r, ellipsisMask: i, newAxisMask: a, shrinkAxisMask: c }; for (let I = 0; I < d.dims; I++)u && 1 << I & a && d.numAddAxisAfterEllipsis++, 1 << I & i && (u = !0); u || (d.ellipsisMask |= 1 << d.dims, d.dims++); const h = { dims: n.length, beginMask: 0, endMask: 0, beginValid: !1, endValid: !1 }; oT(d, h); let p = !0, f = !0, m = !0; const g = [], b = []; for (let I = 0; I < n.length; ++I) { if (h.strides[I] === 0) throw Error(`strides[${I}] must be non-zero`); const y = !!(h.shrinkAxisMask & 1 << I), C = n[I]; if (C === -1) { g.push(y ? 1 : -1); continue } const w = [h.beginMask & 1 << I, h.endMask & 1 << I], k = [h.strides[I] > 0 ? 0 : -1, h.strides[I] > 0 ? C : C - 1]; if (y && h.strides[I] <= 0) throw Error("only stride 1 allowed on non-range indexing."); m = m && h.strides[I] === 1; const S = !!(h.beginMask & 1 << I && h.endMask & 1 << I); if (h.beginValid && h.endValid) { if (y) { const F = h.begin[I] < 0 ? C + h.begin[I] : h.begin[I]; if (h.begin[I] = F, h.end[I] = h.begin[I] + 1, F < 0 || F >= C) throw Error(`slice index ${h.begin[I]} of dimension ${I} out of bounds.`) } else h.begin[I] = mg(h.begin[I], 0, h.strides[I], C, w, k), h.end[I] = mg(h.end[I], 1, h.strides[I], C, w, k); const G = h.strides[I] === 1 && h.begin[I] === 0 && h.end[I] === C; p = p && G, f = f && (I === 0 && h.strides[I] === 1 || G) } else p = p && h.strides[I] === 1 && S, f = f && (I === 0 && h.strides[I] === 1 || S); let T, R = !1; if (h.beginValid && h.endValid ? (T = h.end[I] - h.begin[I], R = !0) : y ? (T = 1, R = !0) : S && C >= 0 && (h.strides[I] < 0 ? T = -C : T = C, R = !0), R) { let G; T === 0 || T < 0 != h.strides[I] < 0 ? G = 0 : G = Math.trunc(T / h.strides[I]) + (T % h.strides[I] !== 0 ? 1 : 0), g.push(G) } else g.push(-1) } for (let I = 0; I < h.finalShapeGatherIndices.length; ++I) { const y = h.finalShapeGatherIndices[I]; y >= 0 ? b.push(g[y]) : y === Hd && b.push(1) } return { finalShapeSparse: b.filter((I, y) => h.finalShapeGatherIndices[y] !== Hd), finalShape: b, isIdentity: p, sliceDim0: f, isSimpleSlice: m, begin: h.begin, end: h.end, strides: h.strides } } function oT(n, t) { t.beginMask = 0, t.endMask = 0, t.shrinkAxisMask = 0; let e = 0; t.beginValid = n.begin != null, t.endValid = n.end != null, t.begin = new Array(t.dims), t.end = new Array(t.dims), t.strides = new Array(t.dims), t.finalShapeGatherIndices = [], t.finalShapeGatherIndicesSparse = [], t.inputShapeGatherIndicesSparse = new Array(t.dims); for (let s = 0; s < n.dims; s++)if (1 << s & n.ellipsisMask) { const o = Math.min(t.dims - (n.dims - s) + 1 + n.numAddAxisAfterEllipsis, t.dims); for (; e < o; e++)t.begin[e] = 0, t.end[e] = 0, t.strides[e] = 1, t.beginMask |= 1 << e, t.endMask |= 1 << e, t.finalShapeGatherIndices.push(e), t.finalShapeGatherIndicesSparse.push(-1), t.inputShapeGatherIndicesSparse[e] = s } else if (1 << s & n.newAxisMask) t.finalShapeGatherIndices.push(Hd), t.finalShapeGatherIndicesSparse.push(-1); else { if (e === t.begin.length) throw Error(`Index out of range using input dim ${e}; input has only ${t.dims} dims, ${t.begin.length}.`); n.begin != null && (t.begin[e] = n.begin[s]), n.end != null && (t.end[e] = n.end[s]), t.strides[e] = n.strides[s], n.beginMask & 1 << s && (t.beginMask |= 1 << e), n.endMask & 1 << s && (t.endMask |= 1 << e), n.shrinkAxisMask & 1 << s ? (t.finalShapeGatherIndices.push(eT), t.finalShapeGatherIndicesSparse.push(-1), t.shrinkAxisMask |= 1 << e) : (t.finalShapeGatherIndices.push(e), t.finalShapeGatherIndicesSparse.push(s)), t.inputShapeGatherIndicesSparse[e] = s, e++ } } function mg(n, t, e, s, o, r) { if (o[t]) return e > 0 ? r[t] : r[t + 1 & 1]; { const i = n < 0 ? s + n : n; return i < r[0] ? r[0] : i > r[1] ? r[1] : i } } const rT = Object.freeze(Object.defineProperty({ __proto__: null, assertParamsValid: _d, computeFlatOffset: Qd, computeOutShape: Ud, getNormalizedAxes: sT, isSliceContinous: Yd, maskToAxes: nT, parseSliceParams: Wc, sliceInfo: Jd, startForAxis: pg, startIndicesWithElidedDims: ug, stopForAxis: fg, stopIndicesWithElidedDims: dg, stridesForAxis: hg, stridesWithElidedDims: ag }, Symbol.toStringTag, { value: "Module" }));/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class iT { static sgd(t) { return new Zd(t) } static momentum(t, e, s = !1) { return new rg(t, e, s) } static rmsprop(t, e = .9, s = 0, o = null, r = !1) { return new ig(t, e, s, o, r) } static adam(t = .001, e = .9, s = .999, o = null) { return new sg(t, e, s, o) } static adadelta(t = .001, e = .95, s = null) { return new eg(t, e, s) } static adamax(t = .002, e = .9, s = .999, o = null, r = 0) { return new og(t, e, s, o, r) } static adagrad(t, e = .1) { return new ng(t, e) } }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _o = iT;/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aT = (() => typeof requestAnimationFrame < "u" ? requestAnimationFrame : typeof setImmediate < "u" ? setImmediate : n => n())(); function Mc() { return new Promise(n => aT(() => n())) }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jd(n, t) { const e = n[0].length; n.forEach((o, r) => { v(o.length === e, () => `Error in concat${e}D: rank of tensors[${r}] must be the same as the rank of the rest (${e})`) }), v(t >= 0 && t < e, () => `Error in concat${e}D: axis must be between 0 and ${e - 1}.`); const s = n[0]; n.forEach((o, r) => { for (let i = 0; i < e; i++)v(i === t || o[i] === s[i], () => `Error in concat${e}D: Shape of tensors[${r}] (${o}) does not match the shape of the rest (${s}) along the non-concatenated axis ${r}.`) }) } function On(n, t) { const e = n[0].slice(); for (let s = 1; s < n.length; s++)e[t] += n[s][t]; return e }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */var Rn; (function (n) { n[n.FIRST_DIM_SIZE = 0] = "FIRST_DIM_SIZE", n[n.VALUE_ROWIDS = 1] = "VALUE_ROWIDS", n[n.ROW_LENGTHS = 2] = "ROW_LENGTHS", n[n.ROW_SPLITS = 3] = "ROW_SPLITS", n[n.ROW_LIMITS = 4] = "ROW_LIMITS", n[n.ROW_STARTS = 5] = "ROW_STARTS" })(Rn || (Rn = {})); function gg(n, t, e) { let s = new Array; if (e == null && t == null) return s; if (t == null) for (; s.length < n + e.length;)s.push(-1); else s = t.slice(); if (e == null) return s; if (n + e.length !== s.length) throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.rank = ${n + e.length}, but shape.rank = ${s.length}`); for (let o = 1; o < e.length; ++o) { const r = e[o], i = s[s.length - e.length + o], a = s[i]; if (r >= 0) if (a >= 0) { if (a !== r) throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.shape[${o + n}] = ${r} but shape[${o + n}] = ${a}`) } else s[i] = r } return s } function bg(n) { const t = { FIRST_DIM_SIZE: Rn.FIRST_DIM_SIZE, VALUE_ROWIDS: Rn.VALUE_ROWIDS, ROW_LENGTHS: Rn.ROW_LENGTHS, ROW_SPLITS: Rn.ROW_SPLITS, ROW_LIMITS: Rn.ROW_LIMITS, ROW_STARTS: Rn.ROW_STARTS }, e = []; for (const s of n) if (s in t) e.push(t[s]); else break; return e } function xg(n) { return n.length === 0 ? 0 : n[0] === Rn.FIRST_DIM_SIZE ? n.length - 1 : n.length } function yg(n, t) { if (n == null || t == null) return; const e = n.length, s = t.length; if (e >= s) throw new Error(`defaultValue.shape=${n} and ragged tensor flatValues.shape=${t}, are incompatible: defaultValue.rank = ${e} must be less than ragged tensor input flatValues.rank = ${s})`); for (let o = 0; o < Math.min(e, s - 1); ++o) { const r = n[o], i = t[o + 1]; if (r >= 0 && i >= 0 && r !== 1 && r !== i) throw new Error(`defaultValue.shape=${n}, and ragged tensor input flatValues.shape=${t} are incompatible: defaultValue.shape[${o - n.length}] = ${r} but ragged tensor input.flatValues.shape[${o - n.length}] = ${i}`) } }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qd = 30; function Fc(n) { return n <= qd ? n : _l(n, Math.floor(Math.sqrt(n))) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function th(n, t, e) { const s = e * (typeof n == "number" ? n : n[0]), o = t * (typeof n == "number" ? n : n[1]); return [s, o] }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $i(n, t, e, s = !0) { let o = []; if (s) o = o.concat(t.slice(0)), o.push(n[0] / e), o = o.concat(n.slice(1)); else { o = o.concat(n[0]); const r = t.length; for (let i = 0; i < r; ++i)o = o.concat([n[i + 1] / t[i], t[i]]); o = o.concat(n.slice(r + 1)) } return o } function Gi(n, t, e = !0) { const s = []; if (e) { s.push(t); for (let o = t + 1; o < n; ++o)o <= 2 * t ? (s.push(o), s.push(o - (t + 1))) : s.push(o) } else { const o = [], r = []; for (let i = 1; i < n; ++i)i >= t * 2 + 1 || i % 2 === 1 ? r.push(i) : o.push(i); s.push(...o), s.push(0), s.push(...r) } return s } function Li(n, t, e, s = !0) { const o = []; s ? o.push(n[0] / e) : o.push(n[0] * e); for (let r = 1; r < n.length; ++r)r <= t.length ? s ? o.push(t[r - 1] * n[r]) : o.push(n[r] / t[r - 1]) : o.push(n[r]); return o } function eh(n, t) { const e = [0]; for (let s = 0; s < t; ++s)e.push(n[s][0]); return e } function nh(n, t, e) { const s = n.slice(0, 1); for (let o = 0; o < e; ++o)s.push(n[o + 1] - t[o][0] - t[o][1]); return s }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Vc = 1.7580993408473768, zc = 1.0507009873554805;/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const sh = .3275911, oh = .254829592, rh = -.284496736, ih = 1.421413741, ah = -1.453152027, ch = 1.061405429;/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rs(n, t) { if (n.length !== t.length) throw new Error(`Cannot merge real and imag arrays of different lengths. real:${n.length}, imag: ${t.length}.`); const e = new Float32Array(n.length * 2); for (let s = 0; s < e.length; s += 2)e[s] = n[s / 2], e[s + 1] = t[s / 2]; return e } function Ig(n) { const t = new Float32Array(n.length / 2), e = new Float32Array(n.length / 2); for (let s = 0; s < n.length; s += 2)t[s / 2] = n[s], e[s / 2] = n[s + 1]; return { real: t, imag: e } } function Cg(n) { const t = Math.ceil(n.length / 4), e = new Float32Array(t), s = new Float32Array(t); for (let o = 0; o < n.length; o += 4)e[Math.floor(o / 4)] = n[o], s[Math.floor(o / 4)] = n[o + 1]; return { real: e, imag: s } } function wg(n) { const t = Math.floor(n.length / 4), e = new Float32Array(t), s = new Float32Array(t); for (let o = 2; o < n.length; o += 4)e[Math.floor(o / 4)] = n[o], s[Math.floor(o / 4)] = n[o + 1]; return { real: e, imag: s } } function lh(n, t) { const e = n[t * 2], s = n[t * 2 + 1]; return { real: e, imag: s } } function vg(n, t, e, s) { n[s * 2] = t, n[s * 2 + 1] = e } function Sg(n, t) { const e = new Float32Array(n / 2), s = new Float32Array(n / 2); for (let o = 0; o < Math.ceil(n / 2); o++) { const r = (t ? 2 : -2) * Math.PI * (o / n); e[o] = Math.cos(r), s[o] = Math.sin(r) } return { real: e, imag: s } } function kg(n, t, e) { const s = (e ? 2 : -2) * Math.PI * (n / t), o = Math.cos(s), r = Math.sin(s); return { real: o, imag: r } }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uh = "->", cT = /->/g, Tg = ",", Ng = "..."; function dh(n, t) { n = n.replace(/\s/g, ""); const e = (n.length - n.replace(cT, "").length) / uh.length; if (e < 1) throw new Error("Equations without an arrow are not supported."); if (e > 1) throw new Error(`Equation must contain exactly one arrow ("${uh}").`); const [s, o] = n.split(uh); v(s.indexOf(Ng) === -1, () => `The ellipsis notation ("${Ng}") is not supported yet.`); const r = s.split(Tg), i = r.length; if (t !== i) throw new Error(`Expected ${i} input tensors, received ${t}`); if (i > 2) throw new Error("Support for more than 2 input tensors is not implemented yet."); const a = []; for (let h = 0; h < o.length; ++h) { const p = o[h]; if (!r.some(f => f.indexOf(p) !== -1)) throw new Error(`Output subscripts contain the label ${p} not present in the input subscripts.`); a.indexOf(p) === -1 && a.push(p) } for (let h = 0; h < s.length; ++h) { const p = s[h]; a.indexOf(p) === -1 && p !== Tg && a.push(p) } const c = new Array(r.length); for (let h = 0; h < i; ++h) { if (new Set(r[h].split("")).size !== r[h].length) throw new Error(`Found duplicate axes in input component ${r[h]}. Support for duplicate axes in input is not implemented yet.`); c[h] = []; for (let p = 0; p < r[h].length; ++p)c[h].push(a.indexOf(r[h][p])) } const l = a.length, u = o.length, d = []; for (let h = u; h < l; ++h)d.push(h); return { allDims: a, summedDims: d, idDims: c } } function hh(n, t) { let e = new Array(n); e.fill(-1); for (let o = 0; o < t.length; ++o)e[t[o]] = o; const s = []; for (let o = 0; o < n; ++o)e[o] === -1 && s.push(o); return e = e.filter(o => o !== -1), { permutationIndices: e, expandDims: s } } function ph(n, t, e) { const s = new Array(n); for (let o = 0; o < e.length; ++o) { const r = e[o].shape; for (let i = 0; i < t[o].length; ++i)s[t[o][i]] === void 0 ? s[t[o][i]] = r[i] : v(s[t[o][i]] === r[i], () => `Expected dimension ${s[t[o][i]]} at axis ${i} of input shaped ${JSON.stringify(r)}, but got dimension ${r[i]}`) } } function fh(n, t) { const e = n, s = []; let o = 0; n.length === 0 && e.push(-1), o = n.length + 1; for (let i = 0; i < o; ++i)s.push([]); const r = []; for (let i = 0; i < e.length; ++i) { const a = e[i], c = lT(t, a); for (const l of c) r.indexOf(l) === -1 && (s[i].push(l), r.push(l)) } return { path: e, steps: s } } function mh(n) { return n.every((t, e) => t === e) } function lT(n, t) { const e = []; for (let s = 0; s < n.length; ++s)(n[s].length === 0 || n[s].indexOf(t) !== -1 || t === -1) && e.push(s); return e } function gh(n, t, e = 0) { let s = []; if (typeof t == "number") v(n.shape[e] % t === 0, () => "Number of splits must evenly divide the axis."), s = new Array(t).fill(n.shape[e] / t); else { const o = t.reduce((i, a) => (a === -1 && (i += 1), i), 0); v(o <= 1, () => "There should be only one negative value in split array."); const r = t.indexOf(-1); if (r !== -1) { const i = t.reduce((a, c) => c > 0 ? a + c : a); t[r] = n.shape[e] - i } v(n.shape[e] === t.reduce((i, a) => i + a), () => "The sum of sizes must match the size of the axis dimension."), s = t } return s }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Rg(n) {
        return `Received SparseTensor with denseShape[0] = 0 but
  indices.shape[0] = ${n}`
    } function $g(n, t) { return `indices(${n}, 0) is invalid: ${t} < 0` } function Gg(n, t, e) { return `indices(${n}, 0) is invalid: ${t} >= ${e}` }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Lg(n, t) { return `only one output dimension may be -1, not both ${n} and ${t}` } function Eg(n, t) { return `size ${n} must be non-negative, not ${t}` } function Dg() { return "reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero" } function Wg(n, t) {
        const e = Z(n), s = Z(t); return `Input to reshape is a SparseTensor with ${e}
  dense values, but the requested shape requires a multiple of ${s}. inputShape=${n} outputShape= ${t}`
    } function Mg(n, t) { const e = Z(n), s = Z(t); return `Input to reshape is a tensor with ${e} dense values, but the requested shape has ${s}. inputShape=${n} outputShape=${t}` }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bh() { return "segment ids must be >= 0" } function Fg() { return "segment ids are not increasing" } function Vg(n, t) { return `Segment id ${n} out of range [0, ${t}), possibly because segmentIds input is not sorted.` } function zg(n, t, e) { return `Bad: indices[${n}] == ${t} out of range [0, ${e})` }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Xg(n, t) { let e = !1, s; for (n <= qd ? (s = n, e = !0) : s = _l(n, Math.floor(Math.sqrt(n))); !e;)s > t || s === n ? e = !0 : s = _l(n, s + 1); return s } function Ag(n, t, e) { const s = [], o = n.length; for (let r = 0; r < o; r++)r !== t ? s.push(n[r]) : s.push(e); return s } function xh(n, t, e, s) {
        const o = t.shape.length, r = n.shape.length; if (s !== 0 && (s < -o || s > o)) throw new Error(`Expect batchDims in the range of [-${o}, ${o}], but got ${s}`); if (s < 0 && (s += o), s > r) throw new Error(`batchDims (${s}) must be less than rank(x) (
    ${r}).`); if (e < s) throw new Error(`batchDims (${s}) must be less than or equal to axis (${e}).`); for (let d = 0; d < s; ++d)if (n.shape[d] !== t.shape[d]) throw new Error(`x.shape[${d}]: ${n.shape[d]} should be equal to indices.shape[${d}]: ${t.shape[d]}.`); const i = n.shape[e], a = []; let c = 1, l = 1, u = 1; for (let d = 0; d < s; ++d)a.push(n.shape[d]), c *= n.shape[d]; for (let d = s; d < e; d++)a.push(n.shape[d]), l *= n.shape[d]; for (let d = s; d < o; d++)a.push(t.shape[d]); for (let d = e + 1; d < r; d++)a.push(n.shape[d]), u *= n.shape[d]; return { batchSize: c, sliceSize: u, outerSize: l, dimSize: i, outputShape: a }
    } const uT = Object.freeze(Object.defineProperty({ __proto__: null, collectGatherOpShapeInfo: xh, computeOutShape: Ag, segOpComputeOptimalWindowSize: Xg }, Symbol.toStringTag, { value: "Module" }));/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function co(n) { try { return n.map(t => ms(t)) } catch (t) { throw new Error(`Failed to decode encoded string bytes into utf-8, error: ${t}`) } } function Og(n) { return n.map(t => fs(t)) } const dT = Object.freeze(Object.defineProperty({ __proto__: null, ERF_A1: oh, ERF_A2: rh, ERF_A3: ih, ERF_A4: ah, ERF_A5: ch, ERF_P: sh, PARALLELIZE_THRESHOLD: qd, get RowPartitionType() { return Rn }, SELU_SCALE: zc, SELU_SCALEALPHA: Vc, applyActivation: zd, assertAndGetBroadcastShape: gt, assertAxesAreInnerMostDims: Ie, assertParamsConsistent: jd, assignToTypedArray: vg, axesAreInnerMostDims: hd, calculateShapes: Ri, checkEinsumDimSizes: ph, checkPadOnDimRoundingMode: Fe, combineLocations: Nm, combineRaggedTensorToTensorShapes: gg, complexWithEvenIndex: Cg, complexWithOddIndex: wg, computeConv2DInfo: ye, computeConv3DInfo: xs, computeDefaultPad: sd, computeDilation2DInfo: Ii, computeOptimalWindowSize: Fc, computeOutAndReduceShapes: fe, computeOutShape: On, computePool2DInfo: hn, computePool3DInfo: ts, convertConv2DDataFormat: es, decodeEinsumEquation: dh, eitherStridesOrDilationsAreOne: Te, expandShapeToKeepDim: oe, exponent: kg, exponents: Sg, fromStringArrayToUint8: Og, fromUint8ToStringArray: co, getAxesPermutation: Yt, getBroadcastDims: Oo, getComplexWithIndex: lh, getEinsumComputePath: fh, getEinsumPermutation: hh, getFusedBiasGradient: Vd, getFusedDyActivation: Fd, getImageCenter: th, getInnerMostAxes: te, getPermuted: Gi, getRaggedRank: xg, getReductionAxes: ce, getReshaped: $i, getReshapedPermuted: Li, getRowPartitionTypesHelper: bg, getSliceBeginCoords: eh, getSliceSize: nh, getSparseFillEmptyRowsIndicesDenseShapeMismatch: Rg, getSparseFillEmptyRowsNegativeIndexErrorMessage: $g, getSparseFillEmptyRowsOutOfRangeIndexErrorMessage: Gg, getSparseReshapeEmptyTensorZeroOutputDimErrorMessage: Dg, getSparseReshapeInputOutputMismatchErrorMessage: Mg, getSparseReshapeInputOutputMultipleErrorMessage: Wg, getSparseReshapeMultipleNegativeOneOutputDimErrorMessage: Lg, getSparseReshapeNegativeOutputDimErrorMessage: Eg, getSparseSegmentReductionIndicesOutOfRangeErrorMessage: zg, getSparseSegmentReductionNegativeSegmentIdsErrorMessage: bh, getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage: Fg, getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage: Vg, getUndoAxesPermutation: ys, isIdentityPermutation: mh, log: JI, mergeRealAndImagArrays: rs, prepareAndValidate: Bd, prepareSplitSize: gh, segment_util: uT, shouldFuse: Xd, slice_util: rT, splitRealAndImagArrays: Ig, stridesOrDilationsArePositive: js, tupleValuesAreOne: Js, upcastType: Ze, validateDefaultValueShape: yg, validateInput: qS, validateUpdateShape: Ym, warn: Qe }, Symbol.toStringTag, { value: "Module" }));/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */jk();/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Pg = { kernelName: ma, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, Ni(ot(e, "float32"), -1)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const hT = { kernelName: yr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => { const s = Zt(ot(e, "float32")), o = Ge(ft(Gt(1), s)); return re(dt(n, o)) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const pT = { kernelName: Ir, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => { const s = Ge(ft(Zt(ot(e, "float32")), 1)); return dt(n, s) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const fT = { kernelName: Lo, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { let a = n; const c = ce(e.shape, o); return c.length > 0 && (a = ut(a, c)), D(a, e.shape) }, b: () => { let a = n; const c = ce(s.shape, o); return c.length > 0 && (a = ut(a, c)), D(a, s.shape) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const mT = { kernelName: jl, saveAllInputs: !0, gradFunc: (n, t) => { const e = {}; return t.forEach((s, o) => { e[o] = () => n.clone() }), e } };/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const gT = { kernelName: ga, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => kt(e) } } };/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const bT = { kernelName: ba, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => kt(e) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const xT = { kernelName: Cr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, Ge(ft(Gt(1), Zt(ot(e, "float32"))))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const yT = { kernelName: wr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => { const s = Ge(Q(Gt(1), Zt(ot(e, "float32")))); return dt(n, s) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const IT = { kernelName: kr, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { const a = Q(Zt(e), Zt(s)); let c = E(n, dt(s, a)); const l = ce(e.shape, o); return l.length > 0 && (c = ut(c, l)), D(c, e.shape) }, b: () => { const a = Q(Zt(e), Zt(s)); let c = re(E(n, dt(e, a))); const l = ce(s.shape, o); return l.length > 0 && (c = ut(c, l)), D(c, s.shape) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const CT = { kernelName: vr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, Q(Zt(ot(e, "float32")), 1)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const wT = { kernelName: Sr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, ft(Gt(1), Zt(ot(e, "float32")))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function vT(n, t, e, s, o, r) { const i = N(n, "dy", "avgPool3dGrad"), a = N(t, "input", "avgPool3dGrad"); let c = i, l = a, u = !1; a.rank === 4 && (u = !0, c = D(i, [1, i.shape[0], i.shape[1], i.shape[2], i.shape[3]]), l = D(a, [1, a.shape[0], a.shape[1], a.shape[2], a.shape[3]])), v(c.rank === 5, () => `Error in avgPool3dGrad: dy must be rank 5 but got rank ${c.rank}.`), v(l.rank === 5, () => `Error in avgPool3dGrad: input must be rank 5 but got rank ${l.rank}.`), Fe("avgPool3dGrad", o, r); const d = { dy: c, input: l }, h = { filterSize: e, strides: s, pad: o, dimRoundingMode: r }, p = L.runKernel(nu, d, h); return u ? D(p, [p.shape[1], p.shape[2], p.shape[3], p.shape[4]]) : p } const ST = W({ avgPool3dGrad_: vT });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kT = { kernelName: ya, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { filterSize: o, strides: r, pad: i, dimRoundingMode: a } = e; return { x: () => ST(n, s, o, r, i, a) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function TT(n, t, e, s, o) { const r = N(n, "dy", "avgPoolGrad"), i = N(t, "input", "avgPoolGrad"); v(i.rank === r.rank, () => `Rank of input (${i.rank}) does not match rank of dy (${r.rank})`); let a = i, c = r, l = !1; i.rank === 3 && (l = !0, a = D(i, [1, i.shape[0], i.shape[1], i.shape[2]]), c = D(r, [1, r.shape[0], r.shape[1], r.shape[2]])), v(c.rank === 4, () => `Error in avgPoolGrad: dy must be rank 4 but got rank ${c.rank}.`), v(a.rank === 4, () => `Error in avgPoolGrad: input must be rank 4 but got rank ${a.rank}.`); const u = { dy: c, input: a }, d = { filterSize: e, strides: s, pad: o }, h = L.runKernel(eu, u, d); return l ? D(h, [h.shape[1], h.shape[2], h.shape[3]]) : h } const NT = W({ avgPoolGrad_: TT });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const RT = { kernelName: xa, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { filterSize: o, strides: r, pad: i } = e; return { x: () => NT(n, s, o, r, i) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const $T = { kernelName: Ia, inputsToSave: ["a", "b"], gradFunc: (n, t, e) => { const [s, o] = t, { transposeA: r, transposeB: i } = e; return !r && !i ? { a: () => $t(n, o, !1, !0), b: () => $t(s, n, !0, !1) } : !r && i ? { a: () => $t(n, o, !1, !1), b: () => $t(n, s, !0, !1) } : r && !i ? { a: () => $t(o, n, !1, !0), b: () => $t(s, n, !1, !1) } : { a: () => $t(o, n, !0, !0), b: () => $t(n, s, !0, !0) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const GT = { kernelName: Ca, gradFunc: (n, t, e) => { const { blockShape: s, crops: o } = e; return { x: () => Cd(n, s, o) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const LT = { kernelName: YI, gradFunc: (n, t, e) => { const s = e, o = s.inputShape, r = s.shape, i = Array.from(r); for (let c = o.length - 1; c >= 0; c--)if (o[c] === r[c]) i[c] = 1; else if (o[c] !== 1) throw new Error(`broadcastTo(): [${o}] cannot be broadcast to [${r}].`); const a = []; for (let c = 0; c < i.length; c++)i[c] > 1 && a.push(c); return { x: () => ut(n, a, !0) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ET = { kernelName: Tr, gradFunc: n => ({ x: () => n.clone() }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const DT = { kernelName: Nr, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const WT = { kernelName: Rr, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { clipValueMin: o, clipValueMax: r } = e; return { x: () => Be(ss(to(s, o), Ko(s, r)), n, kt(n)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const MT = { kernelName: wa, inputsToSave: ["x"], gradFunc: Pg.gradFunc };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const FT = { kernelName: va, saveAllInputs: !0, gradFunc: (n, t, e) => { const s = t.map(c => c.shape), { axis: o } = e, r = It(o, t[0].shape)[0], i = s.map(c => c[r]); return sn(n, i, r).map(c => () => c) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const VT = { kernelName: Sa, inputsToSave: ["x", "filter"], gradFunc: (n, t, e) => { const [s, o] = t, { dilations: r, strides: i, pad: a, dataFormat: c } = e; return v(Js(r), () => `Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '${r}'`), { x: () => cd(s.shape, n, o, i, a, c), filter: () => Md(s, n, o.shape, i, a, c) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zT = { kernelName: ka, inputsToSave: ["dy", "filter"], gradFunc: (n, t, e) => { const [s, o] = t, { strides: r, pad: i, dataFormat: a, dimRoundingMode: c } = e; return { dy: () => qs(n, o, r, i, a, 1, c), filter: () => Md(n, s, o.shape, r, i, a, c) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function XT(n, t, e, s, o) { let r = n; n.rank === 4 && (r = D(n, [1, n.shape[0], n.shape[1], n.shape[2], n.shape[3]])); let i = t; i.rank === 4 && (i = D(t, [1, t.shape[0], t.shape[1], t.shape[2], t.shape[3]])), v(r.rank === 5, () => `Error in conv3dDerFilter: input must be rank 5, but got shape ${r.shape}.`), v(i.rank === 5, () => `Error in conv3dDerFilter: dy must be rank 5, but got shape ${i.shape}.`), v(e.length === 5, () => `Error in conv3dDerFilter: filterShape must be length 5, but got ${e}.`), v(r.shape[4] === e[3], () => `Error in conv3dDerFilter: depth of input ${r.shape[4]}) must match input depth in filter (${e[3]}.`), v(i.shape[4] === e[4], () => `Error in conv3dDerFilter: depth of dy (${i.shape[4]}) must match output depth for filter (${e[4]}).`); const a = { x: r, dy: i }, c = { strides: s, pad: o, filterShape: e }; return L.runKernel(iu, a, c) } const AT = W({ conv3DBackpropFilter_: XT });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const OT = { kernelName: Ta, inputsToSave: ["x", "filter"], gradFunc: (n, t, e) => { const { dilations: s, strides: o, pad: r } = e; v(Js(s), () => `Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '${s}'`); const [i, a] = t; return { x: () => vm(i.shape, n, a, o, r), filter: () => AT(i, n, a.shape, o, r) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const PT = { kernelName: $r, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(re(Pm(ot(e, "float32"))), n) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const KT = { kernelName: Gr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(Km(ot(e, "float32")), n) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ZT = { kernelName: Na, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { axis: o, exclusive: r, reverse: i } = e; return { x: () => { const a = Yt([o], s.rank); let c = km(n, o, r, !i); return a != null && (c = St(c, a)), c } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const BT = { kernelName: Ra, inputsToSave: ["x", "filter"], gradFunc: (n, t, e) => { const { dilations: s, strides: o, pad: r, dimRoundingMode: i } = e, a = s ?? [1, 1]; v(Js(a), () => `Error in gradient of depthwiseConv2dNative: dilation rates greater than 1 are not yet supported. Got dilations '${a}'`); const [c, l] = t; return v(c.rank === 4, () => `Error in gradient of depthwiseConv2dNative: input must be rank 4, but got rank ${c.rank}.`), v(l.rank === 4, () => `Error in gradient of depthwiseConv2dNative: filter must be rank 4, but got rank ${l.rank}.`), v(c.shape[3] === l.shape[2], () => `Error in gradient of depthwiseConv2d: number of input channels (${c.shape[3]}) must match the inChannels dimension in filter ${l.shape[2]}.`), v(Te(o, a), () => `Error in gradient of depthwiseConv2d: Either strides or dilations must be  1. Got strides ${o} and dilations '${a}'.`), Fe("depthwiseConv2d", r, i), { x: () => lk(c.shape, n, l, o, r, a, i), filter: () => ak(c, n, l.shape, o, r, a, i) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const HT = { kernelName: $a, inputsToSave: ["x", "filter"], gradFunc: (n, t, e) => { const [s, o] = t, r = { x: s, filter: o, dy: n }, i = { x: s, filter: o, dy: n }; return { x: () => L.runKernel(fu, r, e), filter: () => L.runKernel(mu, i, e) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _T = { kernelName: Er, outputsToSave: [!0], gradFunc: (n, t) => { const [e] = t, s = { dy: n, y: e }; return { x: () => L.runKernel(gu, s) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const UT = { kernelName: Dr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t, s = E(ns(re(Zt(e))), 2 / Math.sqrt(Math.PI)); return { x: () => E(n, s) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const YT = { kernelName: Wr, outputsToSave: [!0], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, e) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const QT = { kernelName: La, inputsToSave: ["input"], gradFunc: (n, t) => { const [e] = t; return { input: () => D(n, e.shape) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const JT = { kernelName: Mr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, ns(e)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const jT = { kernelName: Fr, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qT = { kernelName: Vr, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { const a = dt(n, ot(s, "float32")), c = ce(e.shape, o); return c.length > 0 ? D(ut(a, c), e.shape) : a }, b: () => { let a = E(n, ot(e, "float32")); const c = ce(s.shape, o); c.length > 0 && (a = D(ut(a, c), s.shape)); const l = Zt(s); return re(dt(a, ot(l, "float32"))) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const tN = { kernelName: Ea, inputsToSave: ["x", "mean", "variance", "scale"], gradFunc: (n, t, e) => { const { varianceEpsilon: s } = e, [o, r, i, a] = t, c = a ?? Gt(1), l = ce(r.shape, o.shape), u = []; if (r.rank === 1) { for (let y = 0; y < o.shape.length - 1; ++y)u.push(o.shape[y]); u.push(1) } const d = ft(o, r), h = E(n, c), p = Xm(Q(i, Gt(s))), f = E(E(E(p, p), p), Gt(-.5)); return { x: () => r.rank === 1 ? D(E(E(n, Nn(D(p, [1, 1, 1, r.shape[0]]), u)), c), o.shape) : D(E(E(n, p), c), o.shape), mean: () => { let y = E(E(p, Gt(-1)), h); return r.rank === 1 && (y = ut(y, l)), D(y, r.shape) }, variance: () => { let y = E(E(f, d), h); return r.rank === 1 && (y = ut(y, l)), D(y, r.shape) }, scale: () => { const y = E(d, p); let C = E(n, y); return r.rank === 1 && (C = ut(C, l)), D(C, r.shape) }, offset: () => { let y = n; return r.rank === 1 && (y = ut(y, l)), D(y, r.shape) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const eN = { kernelName: Da, inputsToSave: ["x", "indices"], gradFunc: (n, t, e) => { const [s, o] = t, { axis: r } = e, i = It(r, s.shape)[0]; return { x: () => { const c = s.shape, l = o.size, u = c.slice(0, i), d = u.length, h = c.slice(r, c.length).slice(1), p = h.length, f = Kg(0, d), m = Kg(d + 1, d + 1 + p), g = Zg([u, [l], h]), b = D(n, g), x = D(o, [l]), I = Zg([[d], f, m]), y = St(b, I); let C = _m(y, x, s.shape[i]); const w = ys(I); return C = St(C, w), C }, indices: () => o } } }; function Kg(n, t) { const e = []; for (let s = n; s < t; ++s)e.push(s); return e } function Zg(n) { const t = []; for (let e = 0; e < n.length; ++e)for (let s = 0; s < n[e].length; ++s)t.push(n[e][s]); return t }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const nN = { kernelName: zr, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t; return { a: () => kt(e), b: () => kt(s) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const sN = { kernelName: Xr, gradFunc: n => ({ x: () => ot(n, "float32") }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oN = { kernelName: Ar, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rN = { kernelName: Or, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iN = { kernelName: Pr, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aN = { kernelName: Ma, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { alpha: o } = e, r = nn(s, 0); return { x: () => Be(r, n, E(n, o)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const cN = { kernelName: Zr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, Q(e, 1)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const lN = { kernelName: Kr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, ot(e, "float32")) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uN = { kernelName: QI, inputsToSave: [], outputsToSave: [!0], gradFunc: (n, t, e) => { const [s] = t, { axis: o } = e; return { logits: () => { const i = ns(s); return ft(n, E(ut(n, o, !0), i)) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dN(n, t, e, s = 5, o = 1, r = 1, i = .5) { const a = { x: n, y: t, dy: e }, c = { depthRadius: s, bias: o, alpha: r, beta: i }; return L.runKernel(wu, a, c) } const hN = W({ localResponseNormalizationBackprop_: dN });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const pN = { kernelName: Oa, inputsToSave: ["x"], outputsToSave: [!0], gradFunc: (n, t, e) => { const [s, o] = t, { depthRadius: r, bias: i, alpha: a, beta: c } = e; return { x: () => hN(s, o, n, r, i, a, c) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Bg(n, t, e, s) { return t.rank < e.rank && (t = D(t, oe(t.shape, s))), n.rank < e.rank && (n = D(n, oe(n.shape, s))), { x: () => E(n, ot(Xn(e, t), n.dtype)) } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Hg = { kernelName: Pa, inputsToSave: ["x"], outputsToSave: [!0], gradFunc: (n, t, e) => { const s = e, { reductionIndices: o } = s, r = t[0], i = t[1], a = It(o, r.shape), c = Bg(n, i, r, a); return { x: () => c.x() } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const fN = { kernelName: Br, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t; return { a: () => E(n, ot(to(e, s), "float32")), b: () => E(n, ot(Gm(e, s), "float32")) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mN(n, t, e, s, o, r, i) { const a = N(n, "dy", "maxPool3dGrad"), c = N(t, "input", "maxPool3dGrad"), l = N(e, "output", "maxPool3dGrad"); let u = a, d = c, h = l, p = !1; c.rank === 4 && (p = !0, u = D(a, [1, a.shape[0], a.shape[1], a.shape[2], a.shape[3]]), d = D(c, [1, c.shape[0], c.shape[1], c.shape[2], c.shape[3]]), h = D(l, [1, l.shape[0], l.shape[1], l.shape[2], l.shape[3]])), v(u.rank === 5, () => `Error in maxPool3dGrad: dy must be rank 5 but got rank ${u.rank}.`), v(d.rank === 5, () => `Error in maxPool3dGrad: input must be rank 5 but got rank ${d.rank}.`), v(h.rank === 5, () => `Error in maxPool3dGrad: output must be rank 5 but got rank ${h.rank}.`), Fe("maxPool3dGrad", r, i); const f = { dy: u, input: d, output: h }, m = { filterSize: s, strides: o, pad: r, dimRoundingMode: i }, g = L.runKernel(Su, f, m); return p ? D(g, [g.shape[1], g.shape[2], g.shape[3], g.shape[4]]) : g } const gN = W({ maxPool3dGrad_: mN });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const bN = { kernelName: Za, inputsToSave: ["x"], outputsToSave: [!0], gradFunc: (n, t, e) => { const [s, o] = t, { filterSize: r, strides: i, pad: a, dimRoundingMode: c } = e; return { x: () => gN(n, s, o, r, i, a, c) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function xN(n, t, e, s, o, r, i) { const a = N(n, "dy", "maxPoolGrad"), c = N(t, "input", "maxPoolGrad"), l = N(e, "output", "maxPoolGrad"); v(c.rank === a.rank, () => `Rank of input (${c.rank}) does not match rank of dy (${a.rank})`), v(a.rank === 4, () => `Error in maxPoolGrad: dy must be rank 4 but got rank ${a.rank}.`), v(c.rank === 4, () => `Error in maxPoolGrad: input must be rank 4 but got rank ${c.rank}.`), Fe("maxPoolGrad", r, i); const u = { dy: a, input: c, output: l }, d = { filterSize: s, strides: o, pad: r, dimRoundingMode: i }; return L.runKernel(vu, u, d) } const yN = W({ maxPoolGrad_: xN });/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const IN = { kernelName: Ka, inputsToSave: ["x"], outputsToSave: [!0], gradFunc: (n, t, e) => { const [s, o] = t, { filterSize: r, strides: i, pad: a } = e; return { x: () => yN(n, s, o, r, i, a) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const CN = { kernelName: Ba, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { axis: o } = e, r = It(o, s.shape), a = fe(s.shape, r)[1], c = Z(a); return { x: () => { const u = s.shape.slice(); r.forEach(p => { u[p] = 1 }); const d = D(n, u); return dt(E(d, eo(s.shape, "float32")), c) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const wN = { kernelName: Ha, inputsToSave: ["x"], outputsToSave: [!0], gradFunc: (n, t, e) => { const s = e, { axis: o } = s, [r, i] = t, a = It(o, r.shape), c = Bg(n, i, r, a); return { x: () => c.x() } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const vN = { kernelName: Hr, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t; return { a: () => E(n, ot(Ko(e, s), "float32")), b: () => E(n, ot(nn(e, s), "float32")) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const SN = { kernelName: _a, inputsToSave: ["x"], gradFunc: (n, t, e) => { const s = t[0], { paddings: o } = e, r = o.map(i => i[0]); return { x: () => Vt(n, r, s.shape) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kN = { kernelName: _r, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { const a = ce(e.shape, o); return a.length > 0 ? D(ut(n, a), e.shape) : n }, b: () => { const a = E(n, re($c(dt(e, s)))), c = ce(s.shape, o); return c.length > 0 ? D(ut(a, c), s.shape) : a } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const TN = { kernelName: Ur, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { const a = E(n, ot(s, "float32")), c = ce(e.shape, o); return c.length > 0 ? D(ut(a, c), e.shape) : a }, b: () => { const a = E(n, ot(e, "float32")), c = ce(s.shape, o); return c.length > 0 ? D(ut(a, c), s.shape) : a } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const NN = { kernelName: Ua, gradFunc: n => ({ x: () => re(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const RN = { kernelName: Ja, inputsToSave: ["indices"], gradFunc: (n, t) => { const e = t[0]; return { indices: () => me(e.shape, "float32") } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const $N = { kernelName: Qa, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const GN = { kernelName: ja, saveAllInputs: !0, gradFunc: (n, t, e) => { const { axis: s } = e; return ro(n, s).map(r => () => r) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _g = { kernelName: qa, inputsToSave: ["x"], gradFunc: (n, t, e) => { const s = t[0], { paddings: o } = e, r = o.map(i => i[0]); return { x: () => Vt(n, r, s.shape) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const LN = { kernelName: Yr, inputsToSave: ["a", "b"], outputsToSave: [!0], gradFunc: (n, t) => { const [e, s, o] = t, r = e, i = s, a = gt(r.shape, i.shape); return { a: () => { const u = ot(i, "float32"); let d = E(n, E(u, Po(r, ft(u, Gt(1))))); const h = ce(r.shape, a); return h.length > 0 && (d = ut(d, h)), D(d, r.shape) }, b: () => { const u = nn(r, 0), d = Be(u, An(r), kt(r)); let h = E(n, E(o, d)); const p = ce(i.shape, a); return p.length > 0 && (h = ut(h, p)), D(h, i.shape) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const EN = { kernelName: tc, inputsToSave: ["x", "alpha"], gradFunc: (n, t) => { const [e, s] = t, o = nn(e, 0); return { x: () => Be(o, n, E(n, s)), alpha: () => { let r = Be(o, kt(n), E(n, e)); const i = ce(s.shape, n.shape); return i.length > 0 && (r = ut(r, i)), D(r, s.shape) } } } };/**
 * @license
 * Copyright 2022 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function DN(n, t, e) { const s = n.shape.slice(); s[e] = 1; const o = D(t, s), r = ud(n, e, !0, !1), i = ud(n, e, !0, !0), a = E(r, i); return E(o, a) } function WN(n, t, e) { const s = n.shape.length, o = s - e.length, r = Yt(e, s); let i = n; r != null && (i = St(n, r)); const a = i.shape.slice(), l = a.splice(s - e.length, e.length).reduce((h, p) => h * p, 1); a.push(l); const u = i.reshape(a); let d = DN(u, t, o); if (d = d.reshape(i.shape), r != null) { const h = ys(r); d = St(d, h) } return d } const MN = { kernelName: ec, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { axis: o } = e; let r = []; return o == null ? r = s.shape.map((i, a) => a) : typeof o == "number" ? r = [o] : r = o, { x: () => WN(s, n, r) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const FN = { kernelName: Lr, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { const a = dt(n, ot(s, "float32")), c = ce(e.shape, o); return c.length > 0 ? D(ut(a, c), e.shape) : a }, b: () => { let a = E(n, ot(e, "float32")); const c = ce(s.shape, o); c.length > 0 && (a = D(ut(a, c), s.shape)); const l = Zt(s); return re(dt(a, ot(l, "float32"))) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const VN = { kernelName: Qr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, re(Zt(e))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zN = { kernelName: jr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t, s = E(Ko(e, 6), Ni(e)); return { x: () => E(n, ot(s, "float32")) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const XN = { kernelName: Jr, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, ot(Ni(e), "float32")) } } };/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const AN = { kernelName: nc, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => D(n, e.shape) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ON = { kernelName: oc, inputsToSave: ["images"], gradFunc: (n, t, e) => { const [s] = t, o = { dy: n, images: s }; return { images: () => L.runKernel(Lu, o, e) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const PN = { kernelName: sc, inputsToSave: ["images"], gradFunc: (n, t, e) => { const [s] = t, o = { dy: n, images: s }; return { images: () => L.runKernel(Gu, o, e) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const KN = { kernelName: rc, gradFunc: (n, t, e) => { const { dims: s } = e, o = It(s, n.shape); return { x: () => oo(n, o) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ZN = { kernelName: qr, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const BN = { kernelName: ti, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => re(dt(n, E(Po(e, 1.5), 2))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const HN = { kernelName: ic, inputsToSave: ["condition"], gradFunc: (n, t) => { const [e] = t; return { condition: () => ot(kt(e), "float32"), t: () => E(n, ot(e, n.dtype)), e: () => E(n, ot(gd(e), n.dtype)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _N = { kernelName: ei, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => { const s = nn(e, Gt(0)), o = Gt(Vc), r = Gt(zc), i = E(n, r), a = E(E(n, o), ns(ot(e, "float32"))); return Be(s, i, a) } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const UN = { kernelName: ri, outputsToSave: [!0], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, E(e, ft(Gt(1), e))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const YN = { kernelName: oi, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const QN = { kernelName: ni, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(ld(ot(e, "float32")), n) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const JN = { kernelName: si, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(Sm(ot(e, "float32")), n) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const jN = { kernelName: ac, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { begin: o, size: r } = e, i = s.shape, [a, c] = Wc(s, o, r), l = []; for (let u = 0; u < n.rank; u++)l.push([a[u], i[u] - a[u] - c[u]]); return { x: () => Id(n, l) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qN = { kernelName: dc, outputsToSave: [!0], gradFunc: (n, t, e) => { const [s] = t, { dim: o } = e, r = !0, i = E(n, s); return { logits: () => ft(i, E(ut(i, [o], r), s)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const tR = { kernelName: ii, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, Ao(e)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ug = { kernelName: lc, gradFunc: (n, t, e) => { const { blockShape: s, paddings: o } = e; return { x: () => ad(n, s, o) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Yg = { kernelName: uc, gradFunc: (n, t, e) => { const { axis: s } = e; return { x: () => Ve(n, s) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const eR = { kernelName: ai, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, E(Ge(ot(e, "float32")), 2)) } } };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const nR = { kernelName: Eu, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => E(n, E(ot(e, "float32"), 2)) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const sR = { kernelName: ci, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = Gt(2); return { a: () => E(n, E(o, ft(e, s))), b: () => E(n, E(o, ft(s, e))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oR = { kernelName: pi, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rR = { kernelName: li, inputsToSave: ["a", "b"], gradFunc: (n, t) => { const [e, s] = t, o = gt(e.shape, s.shape); return { a: () => { let a = n; const c = ce(e.shape, o); return c.length > 0 && (a = ut(a, c)), D(a, e.shape) }, b: () => { let a = n; const c = ce(s.shape, o); return c.length > 0 && (a = ut(a, c)), D(re(a), s.shape) } } } };/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iR = { kernelName: cc, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, o = s.shape.slice(), { axis: r } = e; It(r, s.shape).forEach(l => { o[l] = 1 }); const a = D(n, o), c = E(a, eo(s.shape, "float32")); return { x: () => c } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aR = { kernelName: ui, inputsToSave: ["x"], gradFunc: (n, t) => { const [e] = t; return { x: () => dt(n, Zt(ld(e))) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const cR = { kernelName: di, outputsToSave: [!0], gradFunc: (n, t) => { const [e] = t; return { x: () => E(ft(Gt(1), Zt(e)), n) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const lR = { kernelName: hi, inputsToSave: ["x"], gradFunc: (n, t, e) => { const [s] = t, { reps: o } = e; return { x: () => { let i = kt(s); if (s.rank === 1) for (let a = 0; a < o[0]; ++a)i = Q(i, Vt(n, [a * s.shape[0]], [s.shape[0]])); else if (s.rank === 2) for (let a = 0; a < o[0]; ++a)for (let c = 0; c < o[1]; ++c)i = Q(i, Vt(n, [a * s.shape[0], c * s.shape[1]], [s.shape[0], s.shape[1]])); else if (s.rank === 3) for (let a = 0; a < o[0]; ++a)for (let c = 0; c < o[1]; ++c)for (let l = 0; l < o[2]; ++l)i = Q(i, Vt(n, [a * s.shape[0], c * s.shape[1], l * s.shape[2]], [s.shape[0], s.shape[1], s.shape[2]])); else if (s.rank === 4) for (let a = 0; a < o[0]; ++a)for (let c = 0; c < o[1]; ++c)for (let l = 0; l < o[2]; ++l)for (let u = 0; u < o[3]; ++u)i = Q(i, Vt(n, [a * s.shape[0], c * s.shape[1], l * s.shape[2], u * s.shape[3]], [s.shape[0], s.shape[1], s.shape[2], s.shape[3]])); else throw new Error(`Gradient for tile operation is not implemented for rank-${s.rank} tensors yet.`); return i } } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uR = { kernelName: Eo, gradFunc: (n, t, e) => { const s = e, { perm: o } = s, r = ys(o); return { x: () => St(n, r) } } };/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const dR = { kernelName: hc, gradFunc: (n, t, e) => { const s = e, { axis: o } = s; return { value: () => os(n, o) } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const hR = { kernelName: pc, inputsToSave: ["segmentIds"], gradFunc: (n, t) => { const [e] = t; return { x: () => pR(n, e) } } }; function pR(n, t) { const e = Is(t, kt(t)), s = pd(n, e); let o = to(t, Gt(0, "int32")); const r = s.rank - o.rank; for (let a = 0; a < r; ++a)o = He(o, a + 1); o = ss(o, eo(s.shape, "bool")); const i = kt(s); return Be(o, s, i) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const fR = { kernelName: fc, gradFunc: n => ({ x: () => kt(n) }) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const mR = [Pg, hT, pT, fT, mT, gT, bT, xT, yT, IT, CT, wT, kT, RT, $T, GT, LT, ET, DT, WT, MT, FT, zT, VT, OT, PT, KT, ZT, BT, HT, FN, _T, UT, YT, QT, JT, qT, jT, tN, eN, nN, sN, oN, rN, iN, aN, cN, lN, uN, pN, Hg, Hg, fN, bN, IN, CN, wN, vN, SN, kN, TN, NN, RN, $N, GN, _g, _g, LN, EN, MN, VN, zN, XN, AN, ON, PN, KN, ZN, BN, HN, _N, UN, YN, QN, JN, jN, qN, tR, Ug, Ug, Yg, Yg, eR, sR, nR, oR, rR, iR, aR, cR, lR, uR, dR, hR, fR]; for (const n of mR) jI(n);/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.abs = function () { return this.throwIfDisposed(), $e(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.acos = function () { return this.throwIfDisposed(), qC(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.acosh = function () { return this.throwIfDisposed(), ew(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.add = function (n) { return this.throwIfDisposed(), Q(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.all = function (n, t) { return this.throwIfDisposed(), Im(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.any = function (n, t) { return this.throwIfDisposed(), nd(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.argMax = function (n) { return this.throwIfDisposed(), yi(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.argMin = function (n) { return this.throwIfDisposed(), iw(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.asScalar = function () { return this.throwIfDisposed(), v(this.size === 1, () => "The array must have only 1 element."), D(this, []) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.asType = function (n) { return this.throwIfDisposed(), ot(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.as1D = function () { return this.throwIfDisposed(), D(this, [this.size]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.as2D = function (n, t) { return this.throwIfDisposed(), D(this, [n, t]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.as3D = function (n, t, e) { return this.throwIfDisposed(), D(this, [n, t, e]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.as4D = function (n, t, e, s) { return this.throwIfDisposed(), D(this, [n, t, e, s]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.as5D = function (n, t, e, s, o) { return this.throwIfDisposed(), D(this, [n, t, e, s, o]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.asin = function () { return this.throwIfDisposed(), cw(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.asinh = function () { return this.throwIfDisposed(), uw(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.atan = function () { return this.throwIfDisposed(), hw(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.atan2 = function (n) { return this.throwIfDisposed(), fw(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.atanh = function () { return this.throwIfDisposed(), gw(this) }, P().prototype.avgPool = function (n, t, e, s) { return this.throwIfDisposed(), rd(this, n, t, e, s) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.batchToSpaceND = function (n, t) { return this.throwIfDisposed(), ad(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.batchNorm = function (n, t, e, s, o) { return this.throwIfDisposed(), Sc(this, n, t, e, s, o) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.broadcastTo = function (n) { return this.throwIfDisposed(), vi(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.cast = function (n) { return this.throwIfDisposed(), ot(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.ceil = function () { return this.throwIfDisposed(), Kw(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.clipByValue = function (n, t) { return this.throwIfDisposed(), en(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.concat = function (n, t) { return this.throwIfDisposed(), n instanceof se && (n = [n]), Ve([this, ...n], t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.conv1d = function (n, t, e, s, o, r) { return this.throwIfDisposed(), Cm(this, n, t, e, s, o, r) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.conv2dTranspose = function (n, t, e, s, o) { return this.throwIfDisposed(), wm(this, n, t, e, s, o) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.conv2d = function (n, t, e, s, o, r) { return this.throwIfDisposed(), qs(this, n, t, e, s, o, r) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.cos = function () { return this.throwIfDisposed(), ld(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.cosh = function () { return this.throwIfDisposed(), Sm(this) };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.cumprod = function (n, t, e) { return this.throwIfDisposed(), ud(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.cumsum = function (n, t, e) { return this.throwIfDisposed(), km(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.depthToSpace = function (n, t) { return this.throwIfDisposed(), f2(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.depthwiseConv2d = function (n, t, e, s, o, r) { return this.throwIfDisposed(), dd(this, n, t, e, s, o, r) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.dilation2d = function (n, t, e, s, o) { return this.throwIfDisposed(), b2(this, n, t, e, s, o) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.divNoNan = function (n) { return this.throwIfDisposed(), w2(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.div = function (n) { return this.throwIfDisposed(), dt(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.dot = function (n) { return this.throwIfDisposed(), S2(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.elu = function () { return this.throwIfDisposed(), Tc(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.equal = function (n) { return this.throwIfDisposed(), Xn(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.erf = function () { return this.throwIfDisposed(), N2(this) };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.euclideanNorm = function (n, t) { return this.throwIfDisposed(), F2(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.exp = function () { return this.throwIfDisposed(), ns(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.expandDims = function (n) { return this.throwIfDisposed(), He(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.expm1 = function () { return this.throwIfDisposed(), A2(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.fft = function () { return this.throwIfDisposed(), Bm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.flatten = function () { return this.throwIfDisposed(), D(this, [this.size]) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.floor = function () { return this.throwIfDisposed(), $c(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.floorDiv = function (n) { return this.throwIfDisposed(), ym(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.gather = function (n, t) { return this.throwIfDisposed(), pd(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.greaterEqual = function (n) { return this.throwIfDisposed(), to(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.greater = function (n) { return this.throwIfDisposed(), nn(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.ifft = function () { return this.throwIfDisposed(), Dd(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.irfft = function () { return this.throwIfDisposed(), GS(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.isFinite = function () { return this.throwIfDisposed(), Y2(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.isInf = function () { return this.throwIfDisposed(), J2(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.isNaN = function () { return this.throwIfDisposed(), q2(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.leakyRelu = function (n) { return this.throwIfDisposed(), md(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.lessEqual = function (n) { return this.throwIfDisposed(), Ko(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.less = function (n) { return this.throwIfDisposed(), Gm(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.localResponseNormalization = function (n, t, e, s) { return this.throwIfDisposed(), ov(this, n, t, e, s) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logSigmoid = function () { return this.throwIfDisposed(), dv(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logSoftmax = function (n) { return this.throwIfDisposed(), Em(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logSumExp = function (n, t) { return this.throwIfDisposed(), mv(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.log = function () { return this.throwIfDisposed(), An(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.log1p = function () { return this.throwIfDisposed(), Lm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logicalAnd = function (n) { return this.throwIfDisposed(), ss(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logicalNot = function () { return this.throwIfDisposed(), gd(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logicalOr = function (n) { return this.throwIfDisposed(), Dm(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.logicalXor = function (n) { return this.throwIfDisposed(), Iv(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.matMul = function (n, t, e) { return this.throwIfDisposed(), $t(this, n, t, e) }, P().prototype.maxPool = function (n, t, e, s) { return this.throwIfDisposed(), bd(this, n, t, e, s) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.max = function (n, t) { return this.throwIfDisposed(), Tn(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.maximum = function (n) { return this.throwIfDisposed(), Is(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.mean = function (n, t) { return this.throwIfDisposed(), ie(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.min = function (n, t) { return this.throwIfDisposed(), Nc(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.minimum = function (n) { return this.throwIfDisposed(), xd(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.mirrorPad = function (n, t) { return this.throwIfDisposed(), Rv(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.mod = function (n) { return this.throwIfDisposed(), Gv(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.mul = function (n) { return this.throwIfDisposed(), E(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.neg = function () { return this.throwIfDisposed(), re(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.norm = function (n, t, e) { return this.throwIfDisposed(), Rc(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.notEqual = function (n) { return this.throwIfDisposed(), Gc(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.oneHot = function (n, t = 1, e = 0) { return this.throwIfDisposed(), Wm(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.onesLike = function () { return this.throwIfDisposed(), pn(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.pad = function (n, t) { return this.throwIfDisposed(), Id(this, n, t) }, P().prototype.pool = function (n, t, e, s, o, r) { return this.throwIfDisposed(), Av(this, n, t, e, s, o, r) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.pow = function (n) { return this.throwIfDisposed(), Po(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.prelu = function (n) { return this.throwIfDisposed(), wd(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.prod = function (n, t) { return this.throwIfDisposed(), Kv(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.reciprocal = function () { return this.throwIfDisposed(), uS(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.relu = function () { return this.throwIfDisposed(), so(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.relu6 = function () { return this.throwIfDisposed(), Vm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.reshapeAs = function (n) { return this.throwIfDisposed(), D(this, n.shape) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.reshape = function (n) { return this.throwIfDisposed(), D(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.resizeBilinear = function (n, t, e) { return this.throwIfDisposed(), jm(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.resizeNearestNeighbor = function (n, t, e) { return this.throwIfDisposed(), qm(this, n, t, e) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.reverse = function (n) { return this.throwIfDisposed(), oo(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.rfft = function () { return this.throwIfDisposed(), DS(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.round = function () { return this.throwIfDisposed(), zm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.rsqrt = function () { return this.throwIfDisposed(), Xm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.selu = function () { return this.throwIfDisposed(), Am(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.separableConv2d = function (n, t, e, s, o, r) { return this.throwIfDisposed(), Om(this, n, t, e, s, o, r) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sigmoid = function () { return this.throwIfDisposed(), Ao(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sign = function () { return this.throwIfDisposed(), yS(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sin = function () { return this.throwIfDisposed(), Pm(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sinh = function () { return this.throwIfDisposed(), Km(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.slice = function (n, t) { return this.throwIfDisposed(), Vt(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.softmax = function (n) { return this.throwIfDisposed(), Ed(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.softplus = function () { return this.throwIfDisposed(), Si(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.spaceToBatchND = function (n, t) { return this.throwIfDisposed(), Cd(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.split = function (n, t) { return this.throwIfDisposed(), sn(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sqrt = function () { return this.throwIfDisposed(), Ge(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.square = function () { return this.throwIfDisposed(), Zt(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.squaredDifference = function (n) { return this.throwIfDisposed(), MS(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.squeeze = function (n) { return this.throwIfDisposed(), Ti(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.stack = function (n, t) { this.throwIfDisposed(); const e = n instanceof se ? [this, n] : [this, ...n]; return os(e, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.step = function (n) { return this.throwIfDisposed(), Ni(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.stridedSlice = function (n, t, e, s, o, r, i, a) { return this.throwIfDisposed(), AS(this, n, t, e, s, o, r, i, a) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sub = function (n) { return this.throwIfDisposed(), ft(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.sum = function (n, t) { return this.throwIfDisposed(), ut(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.tan = function () { return this.throwIfDisposed(), PS(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.tanh = function () { return this.throwIfDisposed(), id(this) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.tile = function (n) { return this.throwIfDisposed(), Nn(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.toBool = function () { return this.throwIfDisposed(), ot(this, "bool") };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.toFloat = function () { return this.throwIfDisposed(), ot(this, "float32") };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.toInt = function () { return this.throwIfDisposed(), ot(this, "int32") };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.topk = function (n, t) { return this.throwIfDisposed(), BS(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.transpose = function (n) { return this.throwIfDisposed(), St(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.unique = function (n) { return this.throwIfDisposed(), US(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.unsortedSegmentSum = function (n, t) { return this.throwIfDisposed(), _m(this, n, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.unstack = function (n) { return this.throwIfDisposed(), ro(this, n) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.where = function (n, t) { return this.throwIfDisposed(), Be(n, this, t) };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */P().prototype.zerosLike = function () { return this.throwIfDisposed(), kt(this) };/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Pn extends Error { constructor(t) { super(t), Object.setPrototypeOf(this, Pn.prototype) } } class mn extends Error { constructor(t) { super(t), Object.setPrototypeOf(this, mn.prototype) } } class $ extends Error { constructor(t) { super(t), Object.setPrototypeOf(this, $.prototype) } } class bt extends Error { constructor(t) { super(t), Object.setPrototypeOf(this, bt.prototype) } } class yh extends Error { constructor(t) { super(t), Object.setPrototypeOf(this, yh.prototype) } }/**
 * @license
 * Copyright 2022 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Qg { constructor(t) { this.maxEntries = t || 100, this.cache = new Map } get(t) { let e; return this.cache.has(t) && (e = this.cache.get(t), this.cache.delete(t), this.cache.set(t, e)), e } put(t, e) { if (this.cache.has(t)) this.cache.delete(t); else if (this.cache.size >= this.maxEntries) { const s = this.cache.keys().next().value; this.cache.delete(s) } this.cache.set(t, e) } getMaxEntries() { return this.maxEntries } setMaxEntries(t) { if (t < 0) throw new Error(`The maxEntries of LRU caches must be at least 0, but got ${t}.`); if (this.maxEntries > t) for (let e = 0; e < this.maxEntries - t; e++) { const s = this.cache.keys().next().value; this.cache.delete(s) } this.maxEntries = t } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function lo(n, t) { if (Array.isArray(n)) { let e = []; for (let s = 0; s < t; s++)e = e.concat(n); return e } else { const e = new Array(t); return e.fill(n), e } } function Kn(n, t) { if (!n) throw new yh(t) } function Jg(n, t) { let e = 0; for (const s of n) s === t && e++; return e } function ze(n) { return n.length === 1 ? n[0] : n } function Bt(n) { return Array.isArray(n) ? n : [n] } function is(n) { const e = n.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase(); return e[0] !== "_" ? e : "private" + e } function uo(n) { return n.length <= 1 || n.indexOf("_") === -1 ? n : n.replace(/[_]+(\w|$)/g, (t, e) => e.toUpperCase()) } let gn = {}; function Ih(n) { if (n == null) return null; const t = {}; return t.className = n.getClassName(), t.config = n.getConfig(), t } function Ch(n) { if (!(n == null || typeof n != "object")) if (Array.isArray(n)) n.forEach(t => Ch(t)); else { const t = Object.keys(n); for (const e of t) { const s = n[e]; s != null && typeof s == "object" && (!Array.isArray(s) && s.type === "ndarray" && typeof s.value == "number" ? n[e] = s.value : Ch(s)) } } } function Ei(n, t = {}, e = {}, s = "object", o = !1) {
        if (typeof n == "string") {
            const r = n; let i; if (r in e) i = e[r]; else if (r in gn) i = gn[r]; else if (i = t[r], i == null) throw new $(`Unknown ${s}: ${n}. This may be due to one of the following reasons:
1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`); return i
        } else {
            const r = n; if (r.className == null || r.config == null) throw new $(`${s}: Improper config format: ${JSON.stringify(r)}.
'className' and 'config' must set.`); const i = r.className; let a, c; if (i in e ? [a, c] = e[i] : i in gn ? [a, c] = gn.className : i in t && ([a, c] = t[i]), a == null) throw new $(`Unknown ${s}: ${i}. This may be due to one of the following reasons:
1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`); if (c != null) { const l = {}; for (const p of Object.keys(gn)) l[p] = gn[p]; for (const p of Object.keys(e)) l[p] = e[p]; const u = r.config; u.customObjects = l; const d = Object.assign({}, gn); for (const p of Object.keys(e)) gn[p] = e[p]; Ch(r.config); const h = c(a, r.config, e, o); return gn = Object.assign({}, d), h } else { const l = Object.assign({}, gn); for (const d of Object.keys(e)) gn[d] = e[d]; const u = new a(r.config); return gn = Object.assign({}, l), u }
        }
    } function gR(n, t) { return n < t ? -1 : n > t ? 1 : 0 } function Xc(n, t) { return -1 * gR(n, t) } function ws(n) { if (n == null) return n; const t = []; for (const e of n) t.indexOf(e) === -1 && t.push(e); return t } function bR(n) { if (n == null) throw new $(`Invalid value in obj: ${JSON.stringify(n)}`); for (const t in n) if (n.hasOwnProperty(t)) return !1; return !0 } function ho(n, t, e) { if (e != null && n.indexOf(e) < 0) throw new $(`${e} is not a valid ${t}.  Valid values are ${n} or null/undefined.`) } function wh(n, t, e = 0, s = 1 / 0) { return Kn(e >= 0), Kn(s >= e), Array.isArray(n) && n.length >= e && n.length <= s && n.every(o => typeof o === t) } function ge(n, t) { Array.isArray(n) ? (v(n.length > 0, () => `${t} is unexpectedly an empty array.`), n.forEach((e, s) => ge(e, `element ${s + 1} of ${t}`))) : v(Number.isInteger(n) && n > 0, () => `Expected ${t} to be a positive integer, but got ${jg(n)}.`) } function jg(n) { return n === null ? "null" : Array.isArray(n) ? "[" + n.map(t => jg(t)).join(",") + "]" : typeof n == "string" ? `"${n}"` : `${n}` } function xR(n, t, e) { let s = e != null ? e() : Me(), o; return (...i) => { const a = e != null ? e() : Me(); return a - s < t || (s = a, o = n(...i)), o } } function qg(n) { return n === "relu" ? "relu" : n === "linear" ? "linear" : n === "elu" ? "elu" : null }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */let yR = 0; function t0() { return yR++ } const Ac = {}; function Oc(n = "") { return n in Ac || (Ac[n] = 0), Ac[n] += 1, n + Ac[n].toString() }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const IR = ["channelsFirst", "channelsLast"], CR = ["nearest", "bilinear"], wR = ["valid", "same", "causal"], vR = ["max", "avg"], SR = ["sum", "mul", "concat", "ave"];/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const Uo = new Map; function ee(n) { ho(IR, "DataFormat", n) } function kR(n) { ho(CR, "InterpolationFormat", n) } function rn(n) { ho(wR, "PaddingMode", n) } function e0(n) { ho(vR, "PoolMode", n) } const Di = [], n0 = "/"; function po(n, t) { Di.push(n); try { const e = t(); return Di.pop(), e } catch (e) { throw Di.pop(), e } } function TR() { return Di.length === 0 ? "" : Di.join(n0) + n0 } function s0(n) { if (!r0(n)) throw new Error("Not a valid tensor name: '" + n + "'"); return TR() + n } function o0(n) { if (!r0(n)) throw new Error("Not a valid tensor name: '" + n + "'"); Uo.has(n) || Uo.set(n, 0); const t = Uo.get(n); if (Uo.set(n, Uo.get(n) + 1), t > 0) { const e = `${n}_${t}`; return Uo.set(e, 1), e } else return n } const NR = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/); function r0(n) { return !!n.match(NR) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function RR(n) { return n === parseInt(n.toString(), 10) } function vs(n, t, e) { t == null && (t = 0), e == null && (e = n.length); let s = 1; for (let o = t; o < e; ++o)s *= n[o]; return s } function Yo(n) { if (n.length === 0) return Number.NaN; let t = Number.POSITIVE_INFINITY; for (let e = 0; e < n.length; e++) { const s = n[e]; s < t && (t = s) } return t } function Ss(n) { if (n.length === 0) return Number.NaN; let t = Number.NEGATIVE_INFINITY; for (let e = 0; e < n.length; e++) { const s = n[e]; s > t && (t = s) } return t } function $n(n, t) { if (t < n) throw new $(`end (${t}) < begin (${n}) is forbidden.`); const e = []; for (let s = n; s < t; ++s)e.push(s); return e }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */let vh; function le() { return vh == null && (vh = bs().epsilon()), vh } function Gn() { return "channelsLast" }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Zn(n, t) { return ot(n, t) } function Wi(n, t = -1) { const e = n.shape.slice(); return t < 0 && (t = e.length + t + 1), e.splice(t, 0, 1), D(n, e) } function $R(n, t) { return M(() => { if (n.shape.length !== 2) throw new $(`repeat() expects a rank-2 tensor, but received a rank-${n.shape.length} tensor.`); const e = Wi(n, 1); return Th(e, [1, t, 1]) }) } function GR(n) { const t = [vs(n.shape)]; return D(n, t) } function LR(n) { if (n.rank <= 1) throw new $(`batchFlatten requires a minimum rank of 2. Got rank: ${n.rank}.`); const t = [n.shape[0], vs(n.shape, 1)]; return D(n, t) } function fo(n, t, e) { return M(() => { switch (n.rank) { case 1: return Gd(n, t, e); case 2: return Zm(n, [t, 0], [e, n.shape[1]]); case 3: return Ld(n, [t, 0, 0], [e, n.shape[1], n.shape[2]]); case 4: return Dc(n, [t, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3]]); case 5: return Vt(n, [t, 0, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3], n.shape[4]]); case 6: return Vt(n, [t, 0, 0, 0, 0, 0], [e, n.shape[1], n.shape[2], n.shape[3], n.shape[4], n.shape[5]]); default: throw new $(`sliceAlongFirstAxis() received an unsupported tensor rank: ${n.rank}`) } }) } function Sh(n, t, e) { return M(() => { switch (n.rank) { case 1: return Gd(n, t, e); case 2: return Zm(n, [0, t], [n.shape[0], e]); case 3: return Ld(n, [0, 0, t], [n.shape[0], n.shape[1], e]); case 4: return Dc(n, [0, 0, 0, t], [n.shape[0], n.shape[1], n.shape[2], e]); default: throw new $(`sliceAlongLastAxis() received an unsupported tensor rank: ${n.rank}`) } }) } function Pc(n, t, e, s) { return M(() => { switch (n.rank) { case 1: return Gd(n, t, e); case 2: switch (s) { case 1: return fo(n, t, e); case 2: return Sh(n, t, e); default: throw new $(`The axis is not within the rank of the tensor ${s}`) }case 3: switch (s) { case 1: return fo(n, t, e); case 2: return Ld(n, [0, t, 0], [n.shape[0], e, n.shape[2]]); case 3: return Sh(n, t, e); default: throw new $(`The axis is not within the rank of the tensor ${s}`) }case 4: switch (s) { case 1: return fo(n, t, e); case 2: return Dc(n, [0, t, 0, 0], [n.shape[0], e, n.shape[2], n.shape[3]]); case 3: return Dc(n, [0, 0, t, 0], [n.shape[0], n.shape[1], e, n.shape[3]]); case 4: return Sh(n, t, e); default: throw new $(`The axis is not within the rank of the tensor ${s}`) }default: throw new $(`sliceAlongLastAxis() received an unsupported tensor rank: ${n.rank}`) } }) } function kh(n, t = -1) { let e; return t < 0 && (e = n[0].rank, e !== 0 ? t = e : t = 0), t === n[0].rank && (t = -1), Ve(n, t) } function i0(n, t) { switch (n.rank) { case 1: return Hw([n, t]); case 2: return Uw([n, t], 0); case 3: return Qw([n, t], 0); case 4: return jw([n, t], 0); default: throw new $(`concatAlongFirstAxis() received an unsupported tensor rank: ${n.rank}`) } } function Th(n, t) { if (Array.isArray(t) || (t = [t]), n.rank !== t.length) throw new $(`The length of input n (${t.length}) does not match the number of dimensions in input x (${n.rank})`); return Nn(n, t) } function Kc(n, t = 0, e = 1, s, o) { return iS(n, t, e, s, o) } function Bn(n, t, e, s) { if (n.rank < 2 || t.rank < 2) throw new bt(`dot requires both inputs to be rank >= 2 but got x shape = ${n.shape} and y shape = ${t.shape}`); if (t.rank >= 3) { const o = n.shape.slice(-1)[0], r = t.shape.slice(-2)[0]; if (o !== r) throw new bt(`If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = ${n.shape} and  y shape = ${t.shape}`) } if (n.rank === 2 && t.rank === 2) return Qm({ a: n, b: t, transposeA: !1, transposeB: !1, bias: s ? Nh(n.rank, s, Gn()) : null, activation: e }); { const o = n.shape.slice(), r = o.pop(); n = D(n, [-1, r]); const i = t.shape.slice(), a = i.pop(), c = i.pop(), l = [...i, a], u = Array.from({ length: t.rank }, (f, m) => m === 0 ? t.rank - 2 : m <= t.rank - 2 ? m - 1 : m); t = D(St(t, u), [c, -1]); const d = [...o, ...l]; return D(Qm({ a: n, b: t, transposeA: !1, transposeB: !1, bias: s ? Nh(n.rank, s, Gn()) : null, activation: e }), d) } } function a0(n, t, e) { return M(() => (Array.isArray(t) ? t = on(t, "int32") : t = ot(t, "int32"), pd(n, t, e))) } function Mi(n) { return E(n, n) } function Nh(n, t, e) { const s = t.shape; if (t.rank !== 1 && t.rank !== n) throw new $(`Unexpected bias dimensions: ${t.rank}; expected it to be 1 or ${n}`); if (n === 5) { if (e === "channelsFirst") return s.length === 1 ? D(t, [1, s[0], 1, 1, 1]) : D(t, [1, s[3], s[0], s[1], s[2]]); if (e === "channelsLast") return s.length === 1 ? D(t, [1, 1, 1, 1, s[0]]) : D(t, [1].concat(s)) } else if (n === 4) { if (e === "channelsFirst") return s.length === 1 ? D(t, [1, s[0], 1, 1]) : D(t, [1, s[2], s[0], s[1]]); if (e === "channelsLast") return s.length === 1 ? D(t, [1, 1, 1, s[0]]) : D(t, [1].concat(s)) } else if (n === 3) { if (e === "channelsFirst") return s.length === 1 ? D(t, [1, s[0], 1]) : D(t, [1, s[1], s[0]]); if (e === "channelsLast") return s.length === 1 ? D(t, [1, 1, s[0]]) : D(t, [1].concat(s)) } else if (n < 3) return t; throw new $(`Unsupported input rank by biasAdd: ${t.rank}`) } function Ln(n, t, e) { return M(() => (e == null && (e = Gn()), ee(e), Q(n, Nh(n.rank, t, e)))) } function ER(n, t = 1) { if (t !== 1) throw new bt(`Support for alpha values other than 1 (${t}) is not implemented yet.`); return Tc(n) } function DR(n) { return M(() => dt(n, Q($e(n), 1))) } function c0(n, t, e, s) { return M(() => nk(n, t, e, s)) } function WR(n) { return M(() => { const t = Q(.5, E(.2, n)); return en(t, 0, 1) }) } function Fi(n, t, e = !1) { return e ? n() : t() }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const MR = ["fanIn", "fanOut", "fanAvg"], FR = ["normal", "uniform", "truncatedNormal"];/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function VR(n) { ho(MR, "FanMode", n) } function zR(n) { ho(FR, "Distribution", n) } class bn extends Ho { fromConfigUsesCustomObjects() { return !1 } getConfig() { return {} } } class l0 extends bn { apply(t, e) { return me(t, e) } } l0.className = "Zeros", _(l0); class Rh extends bn { apply(t, e) { return eo(t, e) } } Rh.className = "Ones", _(Rh); class u0 extends bn { constructor(t) { if (super(), typeof t != "object") throw new $(`Expected argument of type ConstantConfig but got ${t}`); if (t.value === void 0) throw new $(`config must have value set but got ${t}`); this.value = t.value } apply(t, e) { return M(() => E(Gt(this.value), eo(t, e))) } getConfig() { return { value: this.value } } } u0.className = "Constant", _(u0); class d0 extends bn { constructor(t) { super(), this.DEFAULT_MINVAL = -.05, this.DEFAULT_MAXVAL = .05, this.minval = t.minval || this.DEFAULT_MINVAL, this.maxval = t.maxval || this.DEFAULT_MAXVAL, this.seed = t.seed } apply(t, e) { return Lc(t, this.minval, this.maxval, e, this.seed) } getConfig() { return { minval: this.minval, maxval: this.maxval, seed: this.seed } } } d0.className = "RandomUniform", _(d0); class h0 extends bn { constructor(t) { super(), this.DEFAULT_MEAN = 0, this.DEFAULT_STDDEV = .05, this.mean = t.mean || this.DEFAULT_MEAN, this.stddev = t.stddev || this.DEFAULT_STDDEV, this.seed = t.seed } apply(t, e) { if (e = e || "float32", e !== "float32" && e !== "int32") throw new bt(`randomNormal does not support dType ${e}.`); return Kc(t, this.mean, this.stddev, e, this.seed) } getConfig() { return { mean: this.mean, stddev: this.stddev, seed: this.seed } } } h0.className = "RandomNormal", _(h0); class p0 extends bn { constructor(t) { super(), this.DEFAULT_MEAN = 0, this.DEFAULT_STDDEV = .05, this.mean = t.mean || this.DEFAULT_MEAN, this.stddev = t.stddev || this.DEFAULT_STDDEV, this.seed = t.seed } apply(t, e) { if (e = e || "float32", e !== "float32" && e !== "int32") throw new bt(`truncatedNormal does not support dType ${e}.`); return Hm(t, this.mean, this.stddev, e, this.seed) } getConfig() { return { mean: this.mean, stddev: this.stddev, seed: this.seed } } } p0.className = "TruncatedNormal", _(p0); class f0 extends bn { constructor(t) { super(), this.gain = t.gain != null ? t.gain : 1 } apply(t, e) { return M(() => { if (t.length !== 2 || t[0] !== t[1]) throw new $("Identity matrix initializer can only be used for 2D square matrices."); return E(this.gain, $m(t[0])) }) } getConfig() { return { gain: this.gain } } } f0.className = "Identity", _(f0); function XR(n, t = "channelsLast") { let e, s; if (ee(t), n.length === 2) e = n[0], s = n[1]; else if ([3, 4, 5].indexOf(n.length) !== -1) { if (t === "channelsFirst") { const o = vs(n, 2); e = n[1] * o, s = n[0] * o } else if (t === "channelsLast") { const o = vs(n, 0, n.length - 2); e = n[n.length - 2] * o, s = n[n.length - 1] * o } } else { const o = vs(n); e = Math.sqrt(o), s = Math.sqrt(o) } return [e, s] } class _e extends bn { constructor(t) { if (super(), t.scale < 0) throw new $(`scale must be a positive float. Got: ${t.scale}`); this.scale = t.scale == null ? 1 : t.scale, this.mode = t.mode == null ? "fanIn" : t.mode, VR(this.mode), this.distribution = t.distribution == null ? "normal" : t.distribution, zR(this.distribution), this.seed = t.seed } apply(t, e) { const s = XR(t), o = s[0], r = s[1]; let i = this.scale; if (this.mode === "fanIn" ? i /= Math.max(1, o) : this.mode === "fanOut" ? i /= Math.max(1, r) : i /= Math.max(1, (o + r) / 2), this.distribution === "normal") { const a = Math.sqrt(i); if (e = e || "float32", e !== "float32" && e !== "int32") throw new bt(`${this.getClassName()} does not support dType ${e}.`); return Hm(t, 0, a, e, this.seed) } else { const a = Math.sqrt(3 * i); return Lc(t, -a, a, e, this.seed) } } getConfig() { return { scale: this.scale, mode: this.mode, distribution: this.distribution, seed: this.seed } } } _e.className = "VarianceScaling", _(_e); class $h extends _e { constructor(t) { super({ scale: 1, mode: "fanAvg", distribution: "uniform", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } $h.className = "GlorotUniform", _($h); class Gh extends _e { constructor(t) { super({ scale: 1, mode: "fanAvg", distribution: "normal", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } Gh.className = "GlorotNormal", _(Gh); class Lh extends _e { constructor(t) { super({ scale: 2, mode: "fanIn", distribution: "normal", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } Lh.className = "HeNormal", _(Lh); class Eh extends _e { constructor(t) { super({ scale: 2, mode: "fanIn", distribution: "uniform", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } Eh.className = "HeUniform", _(Eh); class Dh extends _e { constructor(t) { super({ scale: 1, mode: "fanIn", distribution: "normal", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } Dh.className = "LeCunNormal", _(Dh); class Wh extends _e { constructor(t) { super({ scale: 1, mode: "fanIn", distribution: "uniform", seed: t == null ? null : t.seed }) } getClassName() { return _e.className } } Wh.className = "LeCunUniform", _(Wh); class m0 extends bn { constructor(t) { if (super(), this.DEFAULT_GAIN = 1, this.gain = t.gain == null ? this.DEFAULT_GAIN : t.gain, this.seed = t.seed, this.seed != null) throw new bt("Random seed is not implemented for Orthogonal Initializer yet.") } apply(t, e) { return M(() => { if (t.length < 2) throw new bt("Shape must be at least 2D."); t[0] * t[1] > 2e3 && console.warn(`Orthogonal initializer is being called on a matrix with more than 2000 (${t[0] * t[1]}) elements: Slowness may result.`); const s = t[0] > t[1] ? [t[1], t[0]] : t, o = Kc(s, 0, 1, "float32"); let r = Qk.gramSchmidt(o); return t[0] > t[1] && (r = St(r)), E(this.gain, r) }) } getConfig() { return { gain: this.gain, seed: this.seed } } } m0.className = "Orthogonal", _(m0); const g0 = { constant: "Constant", glorotNormal: "GlorotNormal", glorotUniform: "GlorotUniform", heNormal: "HeNormal", heUniform: "HeUniform", identity: "Identity", leCunNormal: "LeCunNormal", leCunUniform: "LeCunUniform", ones: "Ones", orthogonal: "Orthogonal", randomNormal: "RandomNormal", randomUniform: "RandomUniform", truncatedNormal: "TruncatedNormal", varianceScaling: "VarianceScaling", zeros: "Zeros" }; function b0(n, t = {}) { return Ei(n, fn.getMap().classNameMap, t, "initializer") } function Qt(n) { return Ih(n) } function Ht(n) { if (typeof n == "string") { const t = n in g0 ? g0[n] : n; if (t === "GlorotNormal") return new Gh; if (t === "GlorotUniform") return new $h; if (t === "HeNormal") return new Lh; if (t === "HeUniform") return new Eh; if (t === "LeCunNormal") return new Dh; if (t === "LeCunUniform") return new Wh; { const e = {}; return e.className = t, e.config = {}, b0(e) } } else return n instanceof bn ? n : b0(n) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Mh(n) { return Array.isArray(n) && Array.isArray(n[0]) } function Zc(n) { return n.length === 0 ? [] : Array.isArray(n[0]) ? n : [n] } function mt(n) { let t; if (Array.isArray(n)) { if (n.length !== 1) throw new $(`Expected Tensor length to be 1; got ${n.length}`); t = n[0] } else t = n; return t } function Nt(n) { if (Array.isArray(n) && Array.isArray(n[0])) { if (n.length === 1) return n = n, n[0]; throw new $(`Expected exactly 1 Shape; got ${n.length}`) } else return n }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Bc(n) { let t = 0; for (const e of n) e.shape.length === 0 ? t += 1 : t += e.shape.reduce((s, o) => s * o); return t }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const x0 = "Variable"; class AR { constructor(t, e = "float32", s = x0, o = !0, r = null) { this.dtype = e ?? "float32", this.shape = t.shape, this.id = t0(), s = s ?? x0, this.originalName = s0(s), this.name = o0(this.originalName), this.trainable_ = o, this.constraint = r, this.val = JS(t, this.trainable_, this.name, this.dtype) } read() { return this.assertNotDisposed(), this.val } write(t) { return this.assertNotDisposed(), OR(this.val, t), this.val.id !== t.id && (this.val.assign(t), this.constraint != null && this.val.assign(this.constraint.apply(this.val))), this } dispose() { this.assertNotDisposed(), this.val.dispose() } assertNotDisposed() { if (this.val.isDisposed) throw new Error(`LayersVariable ${this.name} is already disposed.`) } get trainable() { return this.trainable_ } set trainable(t) { this.trainable_ = t, this.val.trainable = t } } function OR(n, t) { if (n.shape.toString() !== t.shape.toString()) throw new Error("Shape mismatch: " + JSON.stringify(n.shape) + " vs. " + JSON.stringify(t.shape)) } function Fh(n) { return n.map(t => t.read()) } function Vh(n) { n.forEach(t => { t[0].write(t[1]) }) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class ue { constructor(t) { this.dtype = t.dtype, this.shape = t.shape, t.shape != null ? this.ndim = t.shape.length : this.ndim = t.ndim, this.maxNDim = t.maxNDim, this.minNDim = t.minNDim, this.axes = t.axes || {} } } class Hn { constructor(t, e, s, o, r, i, a) { this.dtype = t, this.shape = e, this.sourceLayer = s, this.inputs = o, this.callArgs = r, this.outputTensorIndex = a, this.id = t0(), i != null && (this.originalName = s0(i), this.name = o0(this.originalName)), this.rank = e.length } } let PR = 0; class Hc { constructor(t, e) { this.callArgs = e, this.id = PR++, this.outboundLayer = t.outboundLayer, this.inboundLayers = t.inboundLayers, this.nodeIndices = t.nodeIndices, this.tensorIndices = t.tensorIndices, this.inputTensors = t.inputTensors, this.outputTensors = t.outputTensors, this.inputMasks = t.inputMasks, this.outputMasks = t.outputMasks, this.inputShapes = t.inputShapes, this.outputShapes = t.outputShapes; for (const s of t.inboundLayers) s != null && s.outboundNodes.push(this); t.outboundLayer.inboundNodes.push(this) } getConfig() { const t = []; for (const e of this.inboundLayers) e != null ? t.push(e.name) : t.push(null); return { outboundLayer: this.outboundLayer ? this.outboundLayer.name : null, inboundLayers: t, nodeIndices: this.nodeIndices, tensorIndices: this.tensorIndices } } } let KR = 0; class vt extends Ho { constructor(t = {}) { super(), this._callHook = null, this._addedWeightNames = [], this._stateful = !1, this.id = KR++, this.activityRegularizer = null, this.inputSpec = null, this.supportsMasking = !1, this._trainableWeights = [], this._nonTrainableWeights = [], this._losses = [], this._updates = [], this._built = !1, this.inboundNodes = [], this.outboundNodes = []; let e = t.name; if (!e) { const s = this.getClassName(); e = is(s) + "_" + Oc(s) } if (this.name = e, this.trainable_ = t.trainable == null ? !0 : t.trainable, t.inputShape != null || t.batchInputShape != null) { let s; if (t.batchInputShape != null) s = t.batchInputShape; else if (t.inputShape != null) { let r = null; t.batchSize != null && (r = t.batchSize), s = [r].concat(t.inputShape) } this.batchInputShape = s; let o = t.dtype; o == null && (o = t.inputDType), o == null && (o = "float32"), this.dtype = o } t.weights != null ? this.initialWeights = t.weights : this.initialWeights = null, this._refCount = null, this.fastWeightInitDuringBuild = !1 } static nodeKey(t, e) { return t.name + "_ib-" + e.toString() } getNodeAtIndex(t, e) { if (this.inboundNodes.length === 0) throw new mn(`The layer has never been called and thus has no defined ${e}.`); if (this.inboundNodes.length <= t) throw new $(`Asked to get ${e} at node ${t}, but the layer has only ${this.inboundNodes.length} inbound nodes.`); return this.inboundNodes[t] } getInputAt(t) { return ze(this.getNodeAtIndex(t, "input").inputTensors) } getOutputAt(t) { return ze(this.getNodeAtIndex(t, "output").outputTensors) } get input() { if (this.inboundNodes.length > 1) throw new Pn(`Layer ${this.name} has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use \`getInputAt(nodeIndex)\` instead.`); if (this.inboundNodes.length === 0) throw new Pn(`Layer ${this.name} is not connected, no input to return.`); return ze(this.getNodeAtIndex(0, "input").inputTensors) } get output() { if (this.inboundNodes.length === 0) throw new Pn(`Layer ${this.name} has no inbound nodes.`); if (this.inboundNodes.length > 1) throw new Pn(`Layer ${this.name} has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use \`getOutputAt(nodeIndex)\` instead.`); return ze(this.getNodeAtIndex(0, "output").outputTensors) } get losses() { return this._losses } calculateLosses() { return this.losses.map(t => t()) } get updates() { return this._updates } get built() { return this._built } set built(t) { this._built = t } get trainable() { return this.trainable_ } set trainable(t) { this._trainableWeights.forEach(e => e.trainable = t), this.trainable_ = t } get trainableWeights() { return this.trainable_ ? this._trainableWeights.filter(t => t.trainable) : [] } set trainableWeights(t) { this._trainableWeights = t } get nonTrainableWeights() { return this.trainable ? this._trainableWeights.filter(t => !t.trainable).concat(this._nonTrainableWeights) : this._trainableWeights.concat(this._nonTrainableWeights) } set nonTrainableWeights(t) { this._nonTrainableWeights = t } get weights() { return this.trainableWeights.concat(this.nonTrainableWeights) } get stateful() { return this._stateful } resetStates() { if (!this.stateful) throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.") } assertInputCompatibility(t) { if (t = Bt(t), this.inputSpec == null || this.inputSpec.length === 0) return; const e = Bt(this.inputSpec); if (t.length !== e.length) throw new $(`Layer ${this.name} expects ${e.length} inputs, but it received ${t.length} input tensors. Input received: ${t}`); for (let s = 0; s < t.length; s++) { const o = t[s], r = e[s]; if (r == null) continue; const i = o.rank; if (r.ndim != null && i !== r.ndim) throw new $(`Input ${s} is incompatible with layer ${this.name}: expected ndim=${r.ndim}, found ndim=${i}`); if (r.maxNDim != null && i > r.maxNDim) throw new $(`Input ${s} is incompatible with layer ${this.name}: expected max_ndim=${r.maxNDim}, found ndim=${i}`); if (r.minNDim != null && i < r.minNDim) throw new $(`Input ${s} is incompatible with layer ${this.name}: expected min_ndim=${r.minNDim}, found ndim=${i}.`); if (r.dtype != null && o.dtype !== r.dtype) throw new $(`Input ${s} is incompatible with layer ${this.name} : expected dtype=${r.dtype}, found dtype=${o.dtype}.`); if (r.axes) { const a = o.shape; for (const c in r.axes) { const l = Number(c), u = r.axes[c], d = l >= 0 ? a[l] : a[a.length + l]; if (u != null && [u, null].indexOf(d) === -1) throw new $(`Input ${s} is incompatible with layer ${this.name}: expected axis ${l} of input shape to have value ${u} but got shape ${a}.`) } } if (r.shape != null) for (let a = 0; a < r.shape.length; ++a) { const c = r.shape[a], l = o.shape[a]; if (c != null && l != null && c !== l) throw new $(`Input ${s} is incompatible with layer ${this.name}: expected shape=${r.shape}, found shape=${o.shape}.`) } } } call(t, e) { return t } invokeCallHook(t, e) { this._callHook != null && this._callHook(t, e) } setCallHook(t) { this._callHook = t } clearCallHook() { this._callHook = null } apply(t, e) { e = e || {}, this.assertNotDisposed(); const s = Bt(t); let o = !0; for (const i of s) if (!(i instanceof Hn)) { o = !1; break } let r = !0; for (const i of s) if (i instanceof Hn) { r = !1; break } if (o === r) throw new $("Arguments to apply() must be all SymbolicTensors or all Tensors"); return po(this.name, () => { if (!this.built) { this.assertInputCompatibility(t); const i = []; for (const a of Bt(t)) i.push(a.shape); this.build(ze(i)), this.built = !0, this.initialWeights && this.setWeights(this.initialWeights), this._refCount === null && r && (this._refCount = 1) } if (this.assertInputCompatibility(t), r) { let i = this.call(t, e); const a = Bt(i), c = []; for (let l of a) s.indexOf(l) !== -1 && (l = l.clone()), c.push(l); if (i = ze(c), this.activityRegularizer != null) throw new bt("Layer invocation in the presence of activity regularizer(s) is not supported yet."); return i } else { const i = ZR(t), a = this.computeOutputShape(i); let c; const l = BR(t); if (this.warnOnIncompatibleInputShape(Array.isArray(t) ? i[0] : i), a != null && a.length > 0 && Array.isArray(a[0]) ? c = a.map((u, d) => new Hn(l, u, this, Bt(t), e, this.name, d)) : c = new Hn(l, a, this, Bt(t), e, this.name), this.addInboundNode(t, c, null, null, i, a, e), this._refCount++, this.activityRegularizer != null) throw new bt("Layer invocation in the presence of activity regularizer(s) is not supported yet."); return c } }) } warnOnIncompatibleInputShape(t) { if (this.batchInputShape != null) if (t.length !== this.batchInputShape.length) console.warn(`The rank of the input tensor provided (shape: ${JSON.stringify(t)}) does not match that of the batchInputShape (${JSON.stringify(this.batchInputShape)}) of the layer ${this.name}`); else { let e = !1; this.batchInputShape.forEach((s, o) => { s != null && t[o] != null && t[o] !== s && (e = !0) }), e && console.warn(`The shape of the input tensor (${JSON.stringify(t)}) does not match the expectation of layer ${this.name}: ${JSON.stringify(this.batchInputShape)}`) } } get outputShape() { if (this.inboundNodes == null || this.inboundNodes.length === 0) throw new Pn(`The layer ${this.name} has never been called and thus has no defined output shape.`); const t = []; for (const e of this.inboundNodes) { const s = JSON.stringify(e.outputShapes); t.indexOf(s) === -1 && t.push(s) } if (t.length === 1) { const e = this.inboundNodes[0].outputShapes; return Array.isArray(e) && Array.isArray(e[0]) && e.length === 1 ? e[0] : e } else throw new Pn(`The layer ${this.name} has multiple inbound nodes with different output shapes. Hence the notion of "output shape" is ill-defined for the layer.`) } countParams() { if (!this.built) throw new mn(`You tried to call countParams() on ${this.name}, but the layer is not built yet. Build it first by calling build(batchInputShape).`); return Bc(this.weights) } build(t) { this.built = !0 } getWeights(t = !1) { return Fh(t ? this.trainableWeights : this.weights) } setWeights(t) { M(() => { const e = this.weights; if (e.length !== t.length) throw new $(`You called setWeights(weights) on layer "${this.name}" with a weight list of length ${t.length}, but the layer was expecting ${e.length} weights. Provided weights: ${t}...`); if (e.length === 0) return; const s = [], o = Fh(e); for (let r = 0; r < o.length; ++r) { const i = o[r], a = e[r], c = t[r]; if (!Rt(i.shape, c.shape)) throw new $(`Layer weight shape ${i.shape} not compatible with provided weight shape ${c.shape}`); s.push([a, c]) } Vh(s) }) } addWeight(t, e, s, o, r, i, a, c) { if (this._addedWeightNames.indexOf(t) !== -1) throw new $(`Duplicate weight name ${t} for layer ${this.name}`); this._addedWeightNames.push(t), s == null && (s = "float32"), this.fastWeightInitDuringBuild && (o = c != null ? c() : Ht("zeros")); const l = o.apply(e, s), u = new AR(l, s, t, i, a); return l.dispose(), r != null && this.addLoss(() => r.apply(u.read())), i == null && (i = !0), i ? this._trainableWeights.push(u) : this._nonTrainableWeights.push(u), u } setFastWeightInitDuringBuild(t) { this.fastWeightInitDuringBuild = t } addLoss(t) { t == null || Array.isArray(t) && t.length === 0 || (t = Bt(t), this._losses !== void 0 && this._losses !== null && this.losses.push(...t)) } computeOutputShape(t) { return t } computeMask(t, e) { if (!this.supportsMasking) { if (e != null) if (Array.isArray(e)) e.forEach(s => { if (s != null) throw new TypeError(`Layer ${this.name} does not support masking, but was passed an inputMask.`) }); else throw new TypeError(`Layer ${this.name} does not support masking, but was passed an inputMask.`); return null } return e } addInboundNode(t, e, s, o, r, i, a = null) { const c = Bt(t); e = Bt(e), s = Bt(s), o = Bt(o), r = Zc(r), i = Zc(i); const l = [], u = [], d = []; for (const h of c) l.push(h.sourceLayer), u.push(h.nodeIndex), d.push(h.tensorIndex); new Hc({ outboundLayer: this, inboundLayers: l, nodeIndices: u, tensorIndices: d, inputTensors: c, outputTensors: e, inputMasks: s, outputMasks: o, inputShapes: r, outputShapes: i }, a); for (let h = 0; h < e.length; h++)e[h].sourceLayer = this, e[h].nodeIndex = this.inboundNodes.length - 1, e[h].tensorIndex = h } getConfig() { const t = { name: this.name, trainable: this.trainable }; return this.batchInputShape != null && (t.batchInputShape = this.batchInputShape), this.dtype != null && (t.dtype = this.dtype), t } disposeWeights() { return this.weights.forEach(t => t.dispose()), this.weights.length } assertNotDisposed() { if (this._refCount === 0) throw new Error(`Layer '${this.name}' is already disposed.`) } dispose() { if (!this.built) throw new Error(`Cannot dispose Layer ${this.name} because it has not been built yet.`); if (this._refCount === null) throw new Error(`Cannot dispose Layer ${this.name} because it has not been used yet.`); this.assertNotDisposed(); let t = 0; return --this._refCount === 0 && (t = this.disposeWeights()), { refCountAfterDispose: this._refCount, numDisposedVariables: t } } } function ZR(n) { n = Bt(n); const t = []; for (const e of n) t.push(e.shape); return ze(t) } function BR(n) { return "float32" } function y0(n, t, e) { if ((t == null || e != null && e > 0) && (t = n.sourceLayer, e = n.nodeIndex), t.inboundNodes.length === 0) return [n]; { const s = t.inboundNodes[e]; if (s.inboundLayers.length === 0) return s.inputTensors; { const o = []; for (let r = 0; r < s.inboundLayers.length; r++) { const i = s.inputTensors[r], a = s.inboundLayers[r], c = s.nodeIndices[r], l = y0(i, a, c); for (const u of l) o.indexOf(u) === -1 && o.push(u) } return o } } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Vi extends vt { constructor(t) { if (super({ dtype: t.dtype, name: t.name != null ? t.name : Oc("input").toString() }), t.batchSize == null && (t.batchSize = null), t.sparse == null && (t.sparse = !1), this.trainable = !1, this.built = !0, this.sparse = t.sparse, t.inputShape != null && t.batchInputShape != null) throw new $("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time."); let e = t.batchInputShape; if (e == null) { if (t.inputShape == null) throw new $("An InputLayer should be passed either a `batchInputShape` or an `inputShape`."); e = [t.batchSize].concat(t.inputShape) } else if (t.batchSize != null) throw new $("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer."); const s = t.dtype || "float32"; this.batchInputShape = e, this.dtype = s, this.inputSpec = [{ shape: e }]; const o = new Hn(this.dtype, this.batchInputShape, this, [], {}, this.name); o.nodeIndex = 0, o.tensorIndex = 0, new Hc({ outboundLayer: this, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: [o], outputTensors: [o], inputMasks: [null], outputMasks: [null], inputShapes: [e], outputShapes: [e] }) } apply(t, e) { throw new $(`Cannot pass any input to an InputLayer's apply() method. InputLayer name: ${this.name}`) } dispose() { return { refCountAfterDispose: this._refCount, numDisposedVariables: 0 } } getConfig() { return { batchInputShape: this.batchInputShape, dtype: this.dtype, sparse: this.sparse, name: this.name } } } Vi.className = "InputLayer", _(Vi); function HR(n) { if (n.batchShape == null && n.shape == null) throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension."); if (n.batchShape != null && n.shape != null) throw new $("Please provide either a `shape` or `batchShape` argument to Input, but not both."); let t = n.batchShape; n.shape != null && t == null && (t = [null].concat(n.shape)); let e = n.dtype; return e == null && (e = "float32"), new Vi({ batchInputShape: t, name: n.name, dtype: e, sparse: n.sparse }).inboundNodes[0].outputTensors[0] }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function _R(n, t) { if (n.dtype == null || n.dtype === t.dtype) return t; try { return ot(t, n.dtype) } catch { throw new $(`The dtype of the feed (${t.dtype}) can not be cast to the dtype of the key '${n.name}' (${n.dtype}).`) } } class ks { constructor(t) { if (this.id2Value = {}, this.id2Mask = {}, this.name2Id = {}, t instanceof ks) for (const e in t.id2Value) this.id2Value[e] = t.id2Value[e], e in t.id2Mask && (this.id2Mask[e] = t.id2Mask[e]); else { if (t == null) return; for (const e of t) this.add(e.key, e.value) } } add(t, e, s) { if (this.id2Value[t.id] == null) this.id2Value[t.id] = _R(t, e), this.name2Id[t.name] = t.id, s != null && (this.id2Mask[t.id] = s); else throw new $(`Duplicate key: name=${t.name}, id=${t.id}`); return this } addFeed(t) { this.add(t.key, t.value) } hasKey(t) { return this.id2Value[t.id] != null } names() { return Object.keys(this.name2Id) } getValue(t) { if (t instanceof Hn) { if (this.id2Value[t.id] == null) throw new $(`Nonexistent key: ${t.name}`); return this.id2Value[t.id] } else { const e = this.name2Id[t]; if (e == null) throw new $(`Feed dict has no SymbolicTensor name: ${t}`); return this.id2Value[e] } } getMask(t) { if (t instanceof Hn) { if (this.id2Value[t.id] == null) throw new $(`Nonexistent key: ${t.name}`); return this.id2Mask[t.id] } else { const e = this.name2Id[t]; if (e == null) throw new $(`Feed dict has no SymbolicTensor name: ${t}`); return this.id2Mask[e] } } disposeMasks() { this.id2Mask != null && wt(this.id2Mask) } } const _c = new Qg, Uc = new Qg; function UR(n) { _c != null && _c.setMaxEntries(n), Uc != null && Uc.setMaxEntries(n) } function zi(n, t, e, s) { const o = e == null ? !1 : e.training, r = Array.isArray(n), i = r ? n : [n], a = i.map(f => f.name), c = [], l = t.names(); for (const f of a) l.indexOf(f) !== -1 ? c.push(t.getValue(f)) : c.push(null); s != null && (s.maxNumTensors = -1 / 0, s.minNumTensors = 1 / 0); const u = a.join(",") + "|" + t.names().sort().join(","); let d = _c.get(u), h; if (d == null) { const f = YR(i, t); d = f.sorted, h = f.recipientCounts, _c.put(u, d), Uc.put(u, h) } h = {}, o || Object.assign(h, Uc.get(u)); const p = new ks(t); for (let f = 0; f < d.length; ++f) { if (s != null) { const T = vc().numTensors; T > s.maxNumTensors && (s.maxNumTensors = T), T < s.minNumTensors && (s.minNumTensors = T) } const m = d[f], g = m.sourceLayer; if (g instanceof Vi) continue; const b = [], x = [], I = []; let y = !1; for (const T of m.inputs) { const R = p.getValue(T), G = p.getMask(T); b.push(R), x.push(G), G != null && (y = !0), o || (h[T.name]--, h[T.name] === 0 && !t.hasKey(T) && a.indexOf(T.name) === -1 && !R.isDisposed && T.sourceLayer.stateful !== !0 && I.push(R)) } y && (e = e || {}, e.mask = x[0]); const C = Bt(g.apply(b, e)); let w = null; g.supportsMasking && (w = g.computeMask(b, x)); const k = JR(m), S = Array.isArray(k) ? k : [k]; for (let T = 0; T < S.length; ++T) { p.hasKey(S[T]) || p.add(S[T], C[T], Array.isArray(w) ? w[0] : w); const R = a.indexOf(S[T].name); R !== -1 && (c[R] = C[T]) } o || wt(I) } return p.disposeMasks(), r ? c : c[0] } function YR(n, t) { v(n != null && n.length > 0, () => "Expected at least one fetch, got none"); let e = [], s = {}; if (n.length === 1) { const o = I0(n[0], t); e = o.sorted, s = o.recipientMap } else { const o = new Set; for (const r of n) { const { sorted: i, recipientMap: a } = I0(r, t); for (const c of i) o.has(c.name) || (e.push(c), o.add(c.name)); for (const c in a) s[c] == null && (s[c] = new Set), a[c].forEach(l => s[c].add(l)) } } return { sorted: e, recipientCounts: QR(s) } } function QR(n) { const t = {}; for (const e in n) t[e] = n[e].size; return t } function I0(n, t) { const e = new Set, s = [], o = {}; for (const a of t.names()) e.add(a); const r = [], i = []; for (r.push(n); r.length > 0;) { const a = r[r.length - 1]; if (e.has(a.name)) { r.pop(); continue } const c = i[i.length - 1] === r.length - 1; if (a.inputs.length === 0 || c) r.pop(), s.push(a), e.add(a.name), c && i.pop(); else { i.push(r.length - 1); for (const l of a.inputs) o[l.name] == null && (o[l.name] = new Set), o[l.name].add(a.name), !e.has(l.name) && r.push(l) } } return { sorted: s, recipientMap: o } } function JR(n) { let t; if (n.sourceLayer.inboundNodes.length === 1) t = n.sourceLayer.output; else { let e = null; for (let s = 0; s < n.sourceLayer.inboundNodes.length; ++s)for (const o of n.sourceLayer.inboundNodes[s].outputTensors) if (o.id === n.id) { e = s; break } t = n.sourceLayer.getOutputAt(e) } return t }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */A().registerFlag("TOPOLOGICAL_SORT_CACHE_MAX_ENTRIES", () => 100, UR);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function zh(n, t) { return M(() => Ge(ut(E(n, n), t, !0))) } class Xi extends Ho { getConfig() { return {} } } class C0 extends Xi { constructor(t) { super(), this.defaultMaxValue = 2, this.defaultAxis = 0, this.maxValue = t.maxValue != null ? t.maxValue : this.defaultMaxValue, this.axis = t.axis != null ? t.axis : this.defaultAxis } apply(t) { return M(() => { const e = zh(t, this.axis), s = en(e, 0, this.maxValue); return E(t, dt(s, Q(le(), e))) }) } getConfig() { return { maxValue: this.maxValue, axis: this.axis } } } C0.className = "MaxNorm", _(C0); class w0 extends Xi { constructor(t) { super(), this.defaultAxis = 0, this.axis = t.axis != null ? t.axis : this.defaultAxis } apply(t) { return M(() => dt(t, Q(le(), zh(t, this.axis)))) } getConfig() { return { axis: this.axis } } } w0.className = "UnitNorm", _(w0); class v0 extends Xi { apply(t) { return so(t) } } v0.className = "NonNeg", _(v0); class S0 extends Xi { constructor(t) { super(), this.defaultMinValue = 0, this.defaultMaxValue = 1, this.defaultRate = 1, this.defaultAxis = 0, this.minValue = t.minValue != null ? t.minValue : this.defaultMinValue, this.maxValue = t.maxValue != null ? t.maxValue : this.defaultMaxValue, this.rate = t.rate != null ? t.rate : this.defaultRate, this.axis = t.axis != null ? t.axis : this.defaultAxis } apply(t) { return M(() => { const e = zh(t, this.axis), s = Q(E(this.rate, en(e, this.minValue, this.maxValue)), E(1 - this.rate, e)); return E(t, dt(s, Q(le(), e))) }) } getConfig() { return { minValue: this.minValue, maxValue: this.maxValue, rate: this.rate, axis: this.axis } } } S0.className = "MinMaxNorm", _(S0); const k0 = { maxNorm: "MaxNorm", minMaxNorm: "MinMaxNorm", nonNeg: "NonNeg", unitNorm: "UnitNorm" }; function de(n) { return Ih(n) } function T0(n, t = {}) { return Ei(n, fn.getMap().classNameMap, t, "constraint") } function he(n) { if (n == null) return null; if (typeof n == "string") { const e = { className: n in k0 ? k0[n] : n, config: {} }; return T0(e) } else return n instanceof Xi ? n : T0(n) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */async function mo(n) { if (n == null) return; const t = [], e = [], s = []; for (const o in n) { const r = n[o]; if (typeof r != "number") { const i = r; t.push(i.data()), e.push(o), s.push(i) } } if (t.length > 0) { const o = await Promise.all(t); for (let r = 0; r < o.length; ++r)n[e[r]] = o[r][0]; wt(s) } } function N0(n) { if (n != null) for (const t in n) { const e = n[t]; typeof e != "number" && e.dispose() } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */var R0; (function (n) { n[n.SILENT = 0] = "SILENT", n[n.VERBOSE = 1] = "VERBOSE" })(R0 || (R0 = {})); const jR = 125; class Ai { constructor() { this.validationData = null } setParams(t) { this.params = t } async onEpochBegin(t, e) { } async onEpochEnd(t, e) { } async onBatchBegin(t, e) { } async onBatchEnd(t, e) { } async onTrainBegin(t) { } async onTrainEnd(t) { } setModel(t) { } } class qR { constructor(t, e = 10) { t == null && (t = []), this.callbacks = t, this.queueLength = e } append(t) { this.callbacks.push(t) } setParams(t) { for (const e of this.callbacks) e.setParams(t) } setModel(t) { for (const e of this.callbacks) e.setModel(t) } async onEpochBegin(t, e) { e == null && (e = {}); for (const s of this.callbacks) await s.onEpochBegin(t, e) } async onEpochEnd(t, e) { e == null && (e = {}); for (const s of this.callbacks) await s.onEpochEnd(t, e) } async onBatchBegin(t, e) { e == null && (e = {}); for (const s of this.callbacks) await s.onBatchBegin(t, e) } async onBatchEnd(t, e) { e == null && (e = {}); for (const s of this.callbacks) await s.onBatchEnd(t, e) } async onTrainBegin(t) { t == null && (t = {}); for (const e of this.callbacks) await e.onTrainBegin(t) } async onTrainEnd(t) { t == null && (t = {}); for (const e of this.callbacks) await e.onTrainEnd(t) } } class t$ extends Ai { constructor() { super() } async onEpochBegin(t) { this.seen = 0, this.totals = {} } async onBatchEnd(t, e) { e == null && (e = {}); const s = e.size == null ? 0 : e.size; this.seen += s; for (const o in e) { const r = e[o]; if (typeof r == "number") this.totals.hasOwnProperty(o) || (this.totals[o] = 0), this.totals[o] = this.totals[o] + r * s; else { let i; o in this.totals ? i = this.totals[o] : this.totals[o] = 0; const a = M(() => Q(this.totals[o], E(r, s))); this.totals[o] = a, i != null && i.dispose() } } } async onEpochEnd(t, e) { if (e != null) for (const s of this.params.metrics) this.totals[s] != null && (typeof this.totals[s] == "number" ? e[s] = this.totals[s] / this.seen : M(() => { const o = E(dt(1, this.seen), this.totals[s]); e[s] = o, this.totals[s].dispose(), tn(e[s]) })) } } class e$ extends Ai { async onTrainBegin(t) { this.epoch = [], this.history = {} } async onEpochEnd(t, e) { e == null && (e = {}), this.epoch.push(t); for (const s in e) this.history[s] == null && (this.history[s] = []), this.history[s].push(e[s]) } async syncData() { const t = [], e = [], s = []; for (const r in this.history) { const i = this.history[r]; for (let a = 0; a < i.length; ++a)if (typeof i[a] != "number") { const c = i[a]; t.push(c.data()), e.push(r), s.push(a) } } const o = await Promise.all(t); for (let r = 0; r < o.length; ++r)this.history[e[r]][s[r]].dispose(), this.history[e[r]][s[r]] = o[r][0] } } class n$ extends Ai { constructor(t, e) { if (super(), this.currentEpoch = 0, this.nowFunc = t.nowFunc, this.nextFrameFunc = t.nextFrameFunc || Mc, this.yieldEvery = e || "auto", this.yieldEvery === "auto" && (this.yieldEvery = jR), this.yieldEvery === "never" && t.onYield != null) throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback"); Bl(this.yieldEvery) && (this.maybeWait = xR(this.maybeWait.bind(this), this.yieldEvery, this.nowFunc)), this.trainBegin = t.onTrainBegin, this.trainEnd = t.onTrainEnd, this.epochBegin = t.onEpochBegin, this.epochEnd = t.onEpochEnd, this.batchBegin = t.onBatchBegin, this.batchEnd = t.onBatchEnd, this.yield = t.onYield } async maybeWait(t, e, s) { const o = []; this.yield != null && (await mo(s), o.push(this.yield(t, e, s))), o.push(this.nextFrameFunc()), await Promise.all(o) } async onEpochBegin(t, e) { this.currentEpoch = t, this.epochBegin != null && (await mo(e), await this.epochBegin(t, e)) } async onEpochEnd(t, e) { const s = []; this.epochEnd != null && (await mo(e), s.push(this.epochEnd(t, e))), this.yieldEvery === "epoch" && s.push(this.nextFrameFunc()), await Promise.all(s) } async onBatchBegin(t, e) { this.batchBegin != null && (await mo(e), await this.batchBegin(t, e)) } async onBatchEnd(t, e) { const s = []; this.batchEnd != null && (await mo(e), s.push(this.batchEnd(t, e))), this.yieldEvery === "batch" ? s.push(this.nextFrameFunc()) : Bl(this.yieldEvery) && s.push(this.maybeWait(this.currentEpoch, t, e)), await Promise.all(s) } async onTrainBegin(t) { this.trainBegin != null && (await mo(t), await this.trainBegin(t)) } async onTrainEnd(t) { this.trainEnd != null && (await mo(t), await this.trainEnd(t)) } } function $0(n, t) { return n == null && (n = {}), n instanceof Ai ? [n] : Array.isArray(n) && n[0] instanceof Ai ? n : Bt(n).map(s => new n$(s, t)) } class xn { constructor() { } static registerCallbackConstructor(t, e) { v(t >= 0 && Number.isInteger(t), () => `Verbosity level is expected to be an integer >= 0, but got ${t}`), xn.checkForDuplicate(e), xn.constructors[t] == null && (xn.constructors[t] = []), xn.constructors[t].push(e) } static checkForDuplicate(t) { for (const e in xn.constructors) xn.constructors[+e].forEach(o => { if (o === t) throw new $("Duplicate callback constructor.") }) } static clear() { xn.constructors = {} } static createCallbacks(t) { const e = []; for (const s in xn.constructors) { const o = +s; t >= o && e.push(...xn.constructors[o]) } return e.map(s => new s) } } xn.constructors = {}; function G0(n, t, e, s, o, r, i, a, c) { const l = new e$, u = [new t$, ...xn.createCallbacks(t)]; n != null && u.push(...n), u.push(l); const d = new qR(u); return d.setParams({ epochs: e, initialEpoch: s, samples: o, steps: r, batchSize: i, verbose: t, doValidation: a, metrics: c }), { callbackList: d, history: l } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function as(n, t = {}, e = !1) { return Ei(n, fn.getMap().classNameMap, t, "layer", e) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Yc(n, t) { return M(() => { n.dtype !== "float32" && (n = ot(n, "float32")); const e = ut(Mi(n), t, !0), s = kc(e.shape, le()), o = Ge(Is(e, s)); return dt(n, o) }) } function Qc(n, t) { return M(() => ie(Mi(ft(t, n)), -1)) } function Xh(n, t) { return M(() => ie($e(ft(t, n)), -1)) } function Ah(n, t) { return M(() => { const e = ft(n, t), s = en($e(n), le(), Number.MAX_VALUE), o = $e(dt(e, s)); return E(100, ie(o, -1)) }) } function s$(n, t) { return M(() => { const e = en(t, le(), Number.MAX_VALUE), s = An(Q(1, e)), o = en(n, le(), Number.MAX_VALUE), r = An(Q(1, o)); return ie(Mi(ft(s, r)), -1) }) } function o$(n, t) { return M(() => { const e = Is(0, ft(1, E(n, t))); return ie(Mi(e), -1) }) } function r$(n, t) { return M(() => { const e = Is(0, ft(1, E(n, t))); return ie(e, -1) }) } function i$(n, t) { return M(() => { const e = ut(E(n, t), -1), s = Tn(E(ft(1, n), t), -1); return Is(0, Q(1, ft(s, e))) }) } function a$(n, t) { return M(() => { const e = Math.log(2), s = ft(t, n), o = ft(Q(s, Si(E(-2, s))), e); return ie(o, -1) }) } function Oi(n, t, e = !1) { return M(() => { if (e) t = Ed(t); else { const s = ut(t, t.shape.length - 1, !0); t = dt(t, s) } return t = en(t, le(), 1 - le()), re(ut(E(ot(n, "float32"), An(t)), t.shape.length - 1)) }) } function Jc(n, t, e = !1) { return M(() => { const s = ot($c(GR(n)), "int32"); t = en(t, le(), 1 - le()); const o = t.shape, r = D(Wm(s, o[o.length - 1]), o); return Oi(r, t, e) }) } function c$(n, t) { if (!Rt(n.shape, t.shape)) throw new $(`logits and labels must have the same shape, but got shapes ${JSON.stringify(n.shape)} and ${JSON.stringify(t.shape)}`); return M(() => { const e = so(t), s = re($e(t)); return Q(ft(e, E(t, n)), Lm(ns(s))) }) } function jc(n, t) { return M(() => { let e; return e = en(t, le(), 1 - le()), e = An(dt(e, ft(1, e))), ie(c$(n, e), -1) }) } function l$(n, t) { return M(() => { const e = en(n, le(), 1), s = en(t, le(), 1); return ut(E(n, An(dt(e, s))), -1) }) } function u$(n, t) { return M(() => { const e = An(Q(le(), t)); return ie(ft(t, E(n, e)), -1) }) } function L0(n, t) { return M(() => { const e = Yc(n, -1), s = Yc(t, -1), o = E(e, s); return re(ut(o, -1)) }) } const qc = { meanSquaredError: Qc, meanAbsoluteError: Xh, meanAbsolutePercentageError: Ah, meanSquaredLogarithmicError: s$, squaredHinge: o$, hinge: r$, categoricalHinge: i$, logcosh: a$, categoricalCrossentropy: Oi, sparseCategoricalCrossentropy: Jc, binaryCrossentropy: jc, kullbackLeiblerDivergence: l$, poisson: u$, cosineProximity: L0 }; function Oh(n) { if (typeof n == "string") { if (n in qc) return qc[n]; let t = `Unknown loss ${n}`; throw n.toLowerCase().includes("softmaxcrossentropy") && (t = `Unknown loss ${n}. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy`), new $(t) } else return n }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function E0(n, t) { return M(() => { const e = E(.5, pn(t)), s = Zn(nn(t, e), n.dtype); return ie(Xn(n, s), -1) }) } function D0(n, t) { return M(() => Zn(Xn(yi(n, -1), yi(t, -1)), "float32")) } function d$(n, t) { return M(() => ot(ut(ss(Xn(n, 1), Xn(t, 1))), "float32")) } function h$(n, t) { return M(() => ot(ut(ss(Xn(n, 0), Xn(t, 1))), "float32")) } function p$(n, t) { return M(() => { const e = d$(n, t), s = h$(n, t), o = Q(e, s); return ot(Be(nn(o, 0), dt(e, o), 0), "float32") }) } function f$(n, t) { return jc(n, t) } function m$(n, t) { return n.rank === t.rank && (n = Ti(n, [n.rank - 1])), t = yi(t, -1), t.dtype !== n.dtype && (t = ot(t, n.dtype)), ot(Xn(n, t), "float32") } const g$ = Qc, b$ = Qc, x$ = Xh, y$ = Xh, I$ = Ah, C$ = Ah, W0 = Oi, w$ = L0, M0 = Jc, tl = { binaryAccuracy: E0, categoricalAccuracy: D0, precision: p$, categoricalCrossentropy: W0, sparseCategoricalCrossentropy: M0, mse: g$, MSE: b$, mae: x$, MAE: y$, mape: I$, MAPE: C$, cosine: w$ }; function v$(n) { if (typeof n == "string" && n in tl) return tl[n]; if (typeof n != "string" && n != null) return n; throw new $(`Unknown metric ${n}`) } function el(n) { if (Kn(n !== null, `Unknown LossOrMetricFn ${n}`), typeof n == "string") return n; { let t; for (const e of Object.keys(qc)) if (qc[e] === n) { t = e; break } if (t !== void 0) return t; for (const e of Object.keys(tl)) if (tl[e] === n) { t = e; break } return t !== void 0 ? t : n.name } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function S$(n) { const t = { Adagrad: () => _o.adagrad(.01), Adadelta: () => _o.adadelta(1, .95, le()), Adam: () => _o.adam(.001, .9, .999, le()), Adamax: () => _o.adamax(.002, .9, .999, le(), 0), RMSProp: () => _o.rmsprop(.001, .9, 0, le()), SGD: () => _o.sgd(.01) }; if (t.adagrad = t.Adagrad, t.adadelta = t.Adadelta, t.adam = t.Adam, t.adamax = t.Adamax, t.rmsprop = t.RMSProp, t.sgd = t.SGD, n in t) return t[n](); throw new $(`Unknown Optimizer ${n}`) }/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const F0 = 1 * 1024 * 1024; function V0(n, t, e = !1) { if (n == null || typeof n != "object" || Object.getPrototypeOf(n) !== Object.prototype || !Ph(n)) throw new Error("User-defined metadata is expected to be a JSON object, but is not."); if (e) { const s = JSON.stringify(n); s.length > F0 && console.warn(`User-defined metadata of model "${t}" is too large in size (length=${s.length} when serialized). It is not recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= ${F0}.`) } } function Ph(n) { if (n === null) return !0; if (typeof n == "object") if (Object.getPrototypeOf(n) === Object.prototype) { const t = Object.keys(n); for (const e of t) if (typeof e != "string" || !Ph(n[e])) return !1; return !0 } else if (Array.isArray(n)) { for (const t of n) if (!Ph(t)) return !1; return !0 } else return !1; else { const t = typeof n; return t === "string" || t === "number" || t === "boolean" } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function k$(n, t, e, s = console.log) { const o = N$(n), r = ["Layer (type)", "Input Shape", "Output shape", "Param #"]; o ? (t = t || 90, e = e || [.32, .61, .89, 1]) : (t = t || 115, e = e || [.24, .48, .7, .8, 1]), e[e.length - 1] <= 1 && (e = e.map(u => Math.floor(t * u))); let i; if (!o) { r.push("Receives inputs"), i = []; for (const u in n.nodesByDepth) i.push(...n.nodesByDepth[u]) } s("_".repeat(t)), nl(r, e, s), s("=".repeat(t)); const a = n.layers; for (let u = 0; u < a.length; ++u)o ? R$(a[u], e, s) : $$(a[u], e, i, s), s((u === a.length - 1 ? "=" : "_").repeat(t)); n.checkTrainableWeightsConsistency(); const c = T$(n), l = Bc(n.nonTrainableWeights); s(`Total params: ${c + l}`), s(`Trainable params: ${c}`), s(`Non-trainable params: ${l}`), s("_".repeat(t)) } function T$(n) { let t; return n.collectedTrainableWeights != null ? t = Bc(n.collectedTrainableWeights) : t = Bc(n.trainableWeights), t } function N$(n) { let t = !0; const e = [], s = []; for (const o in n.nodesByDepth) e.push(n.nodesByDepth[o]); for (const o of e) { if (o.length > 1 || o.length === 1 && o[0].inboundLayers.length > 1) { t = !1; break } s.push(...o) } if (t) for (const o of n.layers) { let r = !1; for (const i of o.inboundNodes) if (s.indexOf(i) !== -1) if (r) { t = !1; break } else r = !0; if (!t) break } return t } function nl(n, t, e = console.log) { let s = ""; for (let o = 0; o < n.length; ++o)o > 0 && (s = s.slice(0, s.length - 1) + " "), s += n[o], s = s.slice(0, t[o]), s += " ".repeat(t[o] - s.length); e(s) } function R$(n, t, e) { let s, o; try { o = n.inboundNodes.map(c => JSON.stringify(c.inputShapes)).join(",") } catch { o = "multiple" } try { s = JSON.stringify(n.outputShape) } catch { s = "multiple" } const r = n.name, i = n.getClassName(), a = [`${r} (${i})`, o, s, n.countParams().toString()]; nl(a, t, e) } function $$(n, t, e, s) { let o, r; try { r = n.inboundNodes.map(d => JSON.stringify(d.inputShapes)).join(",") } catch { r = "multiple" } try { o = JSON.stringify(n.outputShape) } catch { o = "multiple" } const i = []; for (const d of n.inboundNodes) if (!(e != null && e.length > 0 && e.indexOf(d) === -1)) for (let h = 0; h < d.inboundLayers.length; ++h) { const p = d.inboundLayers[h].name, f = d.nodeIndices[h], m = d.tensorIndices[h]; i.push(`${p}[${f}][${m}]`) } const a = n.name, c = n.getClassName(), l = i.length === 0 ? "" : i[0], u = [`${a} (${c})`, r, o, n.countParams().toString(), l]; nl(u, t, s); for (let d = 1; d < i.length; ++d)nl(["", "", "", "", i[d]], t, s) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function z0(n, t, e) { return (n === "inboundNodes" || n === "outputLayers" || n === "inputLayers") && t === 0 && typeof e == "string" } function Kh(n, t) { if (n === null) return null; if (typeof n == "string") return uo(n); if (typeof n == "number" || typeof n == "boolean") return n; if (n instanceof Array) { const e = [], s = n.length; for (let o = 0; o < s; ++o) { const r = n[o]; z0(t, o, r) ? e.push(r) : e.push(Kh(r, t)) } return e } else { const e = {}; for (const s of Object.keys(n)) { const o = n[s]; if (s === "name" && typeof o == "string") e[s] = o; else { const r = uo(s); e[r] = Kh(o, r) } } return e } } function Zh(n, t) { if (n == null) return null; if (typeof n == "string") return is(n); if (typeof n == "number" || typeof n == "boolean") return n; if (n instanceof Array) { const e = [], s = n.length; for (let o = 0; o < s; ++o) { const r = n[o]; z0(t, o, r) ? e.push(r) : e.push(Zh(r, t)) } return e } else { const e = {}; for (const s of Object.keys(n)) { const o = n[s], r = is(s); (s === "name" || s === "className") && typeof o == "string" ? e[r] = o : e[r] = Zh(o, s) } return e } }/** @license See the LICENSE file. */const X0 = "4.2.0";/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class En extends vt { constructor(t) { if (super({}), this.containerNodes = new Set, this.name = t.name, this.name == null) { const x = this.getClassName().toLowerCase(); this.name = Oc(x) } if (this.supportsMasking = !1, this.trainable_ = !0, Array.isArray(t.inputs) ? this.inputs = t.inputs.slice() : this.inputs = [t.inputs], Array.isArray(t.outputs) ? this.outputs = t.outputs.slice() : this.outputs = [t.outputs], ws(this.inputs).length !== this.inputs.length) throw new $(`The list of inputs passed to the model is redundant. All inputs should only appear once. Found: ${this.inputs.map(x => x.name)}`); ws(this.outputs).length !== this.outputs.length && console.warn(`The list of outputs passed to the model is redundant. All outputs should only appear once. Found: ${this.outputs.map(x => x.name)}`), this.inputLayers = [], this.inputLayersNodeIndices = [], this.inputLayersTensorIndices = [], this.outputLayers = [], this.outputLayersNodeIndices = [], this.outputLayersTensorIndices = [], this.layers = [], this.internalContainerRefs = []; for (const x of this.outputs) { const I = x.sourceLayer, y = x.nodeIndex, C = x.tensorIndex; this.outputLayers.push(I), this.outputLayersNodeIndices.push(y), this.outputLayersTensorIndices.push(C) } for (const x of this.inputs) { const I = x.sourceLayer, y = x.nodeIndex, C = x.tensorIndex; Kn(y === 0, "input layer has >1 nodes"), Kn(C === 0, "input layer has >1 tensors"), this.inputLayers.push(I), this.inputLayersNodeIndices.push(y), this.inputLayersTensorIndices.push(C) } this.inputNames = [], this.outputNames = [], this.feedInputShapes = [], this.feedInputNames = [], this.feedOutputNames = []; for (let x = 0; x < this.inputLayers.length; x++) { const I = this.inputLayers[x]; if (!(I instanceof Vi)) throw new TypeError(`Input layers to a LayersModel must be InputLayer objects. Received inputs: ${t.inputs}. Input ${x} (0-based) originates from layer type ${I.getClassName()}.`); this.inputNames.push(I.name), this.feedInputShapes.push(I.batchInputShape), this.feedInputNames.push(I.name) } for (const x of this.outputLayers) this.outputNames.push(x.name); this.internalInputShapes = this.inputs.map(x => x.shape), this.internalOutputShapes = this.outputs.map(x => x.shape); const e = {}, s = {}, o = {}, r = {}, i = {}, a = [], c = (x, I, y, C, w, k) => { (C == null || w == null || k == null) && (C = x.sourceLayer, w = x.nodeIndex, k = x.tensorIndex); const S = C.inboundNodes[w]; if (y.indexOf(S) !== -1) throw new mn(`The tensor ${x.name} at layer "${C.name}" is part of a cycle.`); if (I.indexOf(S) !== -1) return; this.containerNodes.add(En.nodeKey(C, w)), C.id in i || (i[C.id] = Object.keys(i).length), y.indexOf(S) === -1 && y.push(S); const T = S.inboundLayers.length; for (let R = 0; R < T; R++) { const G = S.inputTensors[R], F = S.inboundLayers[R], V = S.nodeIndices[R], z = S.tensorIndices[R]; c(G, I, y, F, V, z) } for (I.push(S); y.indexOf(S) >= 0;)y.splice(y.indexOf(S), 1); a.push(S) }, l = [], u = []; for (const x of this.outputs) c(x, l, u); const d = a.slice().reverse(); for (const x of d) { s[x.id] = x, x.id in e || (e[x.id] = 0); let I = e[x.id]; const y = o[x.outboundLayer.id] == null ? 0 : o[x.outboundLayer.id]; I = Math.max(I, y), o[x.outboundLayer.id] = I, r[x.outboundLayer.id] = x.outboundLayer, e[x.id] = I; for (let C = 0; C < x.inboundLayers.length; C++) { const w = x.inboundLayers[C], k = x.nodeIndices[C], S = w.inboundNodes[k], T = e[S.id] == null ? 0 : e[S.id]; e[S.id] = Math.max(I + 1, T), s[S.id] = S } } const h = {}; for (const x in e) { const I = e[x]; I in h || (h[I] = []), h[I].push(s[x]) } const p = {}; for (const x in o) { const I = o[x]; I in p || (p[I] = []), p[I].push(r[x]) } let f = Object.keys(p).map(x => parseInt(x, 10)).sort(Xc); this.layers = []; for (const x of f) { const I = p[x]; I.sort((y, C) => { const w = i[y.id], k = i[C.id]; return w < k ? -1 : w > k ? 1 : 0 }); for (const y of I) y instanceof En && this.internalContainerRefs.push(y), this.layers.push(y) } this.layersByDepth = p, f = Object.keys(h).map(x => parseInt(x, 10)).sort(Xc); const m = this.inputs.slice(), g = []; for (const x of f) for (const I of h[x]) { const y = I.outboundLayer; if (y != null) { for (const C of I.inputTensors) if (m.indexOf(C) === -1) throw new mn(`Graph disconnected: cannot obtain value for tensor ${C} at layer "${y.name}". The following previous layers were accessed without issue: ${g}`); for (const C of I.outputTensors) m.push(C); g.push(y.name) } } this.nodesByDepth = h; const b = this.layers.map(x => x.name); for (const x of b) { const I = b.filter(y => y === x).length; if (I !== 1) throw new mn(`The name "${x}" is used ${I} times in the model. All layer names should be unique. Layer names: ` + JSON.stringify(b)) } this.outboundNodes = [], this.inboundNodes = [], new Hc({ outboundLayer: this, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: this.inputs, outputTensors: this.outputs, inputMasks: this.inputs.map(x => null), outputMasks: this.outputs.map(x => null), inputShapes: this.inputs.map(x => x.shape), outputShapes: this.outputs.map(x => x.shape) }), this.built = !0, this._refCount = 1 } assertNotDisposed() { if (this._refCount === 0) throw new Error(`Container '${this.name}' is already disposed.`) } dispose() { this.assertNotDisposed(); const t = { refCountAfterDispose: null, numDisposedVariables: 0 }; if (--this._refCount === 0) { for (const e of this.layers) t.numDisposedVariables += e.dispose().numDisposedVariables; for (const e of this.internalContainerRefs) t.numDisposedVariables += e.dispose().numDisposedVariables } return t.refCountAfterDispose = this._refCount, t } get trainable() { return this.trainable_ } set trainable(t) { this.layers.forEach(e => { e._trainableWeights.forEach(s => s.trainable = t) }), this.trainable_ = t } get trainableWeights() { if (this._trainableWeights.length > 0) throw new $("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array."); if (!this.trainable) return []; let t = []; for (const e of this.layers) t = t.concat(e.trainableWeights); return t } get nonTrainableWeights() { const t = []; for (const e of this.layers) t.push(...e.nonTrainableWeights); if (!this.trainable) { const e = []; for (const s of this.layers) e.push(...s.trainableWeights); return e.concat(t) } return t } get weights() { return this.trainableWeights.concat(this.nonTrainableWeights) } loadWeights(t, e = !0) { const s = {}; let o = 0; for (const i of this.layers) for (const a of i.weights) { if (s[a.originalName] != null) throw new $(`Duplicate weight name: ${a.originalName}`); s[a.originalName] = a, o++ } const r = []; for (const i in t) { let a = i; if (s[i] == null) { const c = i.split("/"); a = c.slice(0, -2).concat([c[c.length - 1]]).join("/") } if (s[a] != null) r.push([s[a], t[i]]); else if (e) throw new $(`Provided weight data has no target variable: ${i}`); delete s[a] } if (e) { const i = []; for (const a in s) i.push(a); if (i.length > 0) throw new $(`${i.length} of ${o} weights are not set: ${i}`) } Vh(r) } updatedConfig() { const t = this.getConfig(), e = {}; return e.className = this.getClassName(), e.config = t, e.kerasVersion = `tfjs-layers ${X0}`, e.backend = "TensorFlow.js", e } toJSON(t, e = !0) { const s = Zh(this.updatedConfig()); return e ? JSON.stringify(s) : s } call(t, e) { return M(() => { t = Bt(t); const s = new ks; for (let o = 0; o < this.inputs.length; ++o)s.add(this.inputs[o], t[o]); return zi(this.outputs, s, e) }) } computeMask(t, e) { return M(() => { t = Bt(t); let s; return e == null ? s = lo(null, t.length) : s = Bt(e), this.runInternalGraph(t, s)[1] }) } computeOutputShape(t) { const e = Zc(t); if (e.length !== this.inputLayers.length) throw new $(`Invalid inputShape argument ${t}: model has ${this.inputLayers.length} tensor inputs.`); const s = {}; for (let a = 0; a < e.length; a++) { const c = this.inputLayers[a], l = e[a], u = c.name + "_0_0"; s[u] = l } const o = Object.keys(this.nodesByDepth).map(a => parseInt(a, 10)).sort(Xc); if (o.length > 1) for (const a of o) { const c = this.nodesByDepth[a]; for (const l of c) { const u = l.outboundLayer; if (this.inputLayers.map(m => m.id).indexOf(u.id) !== -1) continue; const d = []; for (let m = 0; m < l.inboundLayers.length; m++) { const g = l.inboundLayers[m], b = l.nodeIndices[m], x = l.tensorIndices[m], I = `${g.name}_${b}_${x}`, y = s[I]; d.push(y) } const h = u.computeOutputShape(ze(d)), p = Zc(h), f = u.inboundNodes.indexOf(l); for (let m = 0; m < p.length; m++) { const g = `${u.name}_${f}_${m}`; s[g] = p[m] } } } const r = [], i = []; for (let a = 0; a < this.outputLayers.length; a++) { const c = this.outputLayers[a], l = this.outputLayersNodeIndices[a], u = this.outputLayersTensorIndices[a], d = `${c.name}_${l}_${u}`; i.push(d) } for (let a = 0; a < i.length; a++) { const c = i[a]; Kn(c in s), r.push(s[c]) } return ze(r) } runInternalGraph(t, e) { e == null && (e = lo(null, t.length)); const s = {}; for (let c = 0; c < this.inputs.length; ++c) { const l = this.inputs[c], u = t[c], d = e[c]; s[l.id] = [u, d] } const o = Object.keys(this.nodesByDepth).map(c => parseInt(c, 10)).sort(Xc); for (const c of o) { const l = this.nodesByDepth[c]; for (const u of l) { const d = u.outboundLayer, h = u.inputTensors, p = u.outputTensors, f = new Array; for (const m of h) m.id in s && f.push(s[m.id]); if (f.length === h.length) { let m = {}, g, b, x, I; if (u.callArgs != null && (m = u.callArgs), f.length === 1) { const [y, C] = f[0]; m.mask == null && (m.mask = C), x = Bt(d.call(y, m)), I = Bt(d.computeMask(y, C)), g = [y], b = [C] } else g = f.map(y => y[0]), b = f.map(y => y[1]), m.mask == null && (m.mask = b), x = Bt(d.call(g, m)), I = Bt(d.computeMask(g, b)); if (d.activityRegularizer) throw new bt("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet."); for (let y = 0; y < p.length; ++y) { const C = p[y], w = x[y], k = I[y]; s[C.id] = [w, k] } } } } const r = [], i = [], a = []; for (const c of this.outputs) { Kn(c.id in s, `Could not compute output ${c.name} : ${c.id}`); const [l, u] = s[c.id]; a.push(l.shape), r.push(l), i.push(u) } return [r, i, a] } buildNodeConversionMap(t) { const e = {}; let s; for (const o of this.layers) { s = o instanceof En ? 1 : 0; for (let r = 0; r < o.inboundNodes.length; r++) { const i = En.nodeKey(o, r); this.containerNodes.has(i) && (e[i] = s, s += 1) } } return e } getLayer(t, e) { if (e != null) { if (this.layers.length <= e) throw new $(`Was asked to retrieve layer at index ${e}, but model only has ${this.layers.length} layer(s).`); return this.layers[e] } else if (t == null) throw new $("Provide either a layer name or layer index"); for (const s of this.layers) if (s.name === t) return s; throw new $(`No such layer: ${t}`) } calculateLosses() { return M(() => { const t = []; for (const e of this.layers) for (let s = 0; s < e.inboundNodes.length; ++s) { const o = En.nodeKey(e, s); this.containerNodes.has(o) && t.push(...e.calculateLosses()) } return t }) } getConfig() { const t = { name: this.name }, e = this.buildNodeConversionMap(this.layers), s = []; for (const i of this.layers) { const a = i.getClassName(), c = i.getConfig(), l = []; for (let d = 0; d < i.inboundNodes.length; d++) { const h = i.inboundNodes[d], p = En.nodeKey(i, d); let f = {}; if (this.containerNodes.has(p)) { if (h.callArgs) try { JSON.stringify(h.callArgs), f = h.callArgs } catch { console.warn(`Layer ${i.name} was passed non-serializable keyword arguments: ${h.callArgs}. They will not be included in the serialized model (and thus will be missing at deserialization time).`), f = {} } if (h.inboundLayers.length > 0) { const m = []; for (let g = 0; g < h.inboundLayers.length; g++) { const b = h.inboundLayers[g], x = h.nodeIndices[g], I = h.tensorIndices[g], y = En.nodeKey(b, x); let C = e[y]; C == null && (C = 0), m.push([b.name, C, I, f]) } l.push(m) } } } const u = {}; u.name = i.name, u.className = a, u.config = c, u.inboundNodes = l, s.push(u) } t.layers = s; const o = []; for (let i = 0; i < this.inputLayers.length; i++) { const a = this.inputLayers[i], c = this.inputLayersNodeIndices[i], l = En.nodeKey(a, c); if (!this.containerNodes.has(l)) continue; let u = e[l]; u == null && (u = 0); const d = this.inputLayersTensorIndices[i]; o.push([a.name, u, d]) } t.inputLayers = o; const r = []; for (let i = 0; i < this.outputLayers.length; i++) { const a = this.outputLayers[i], c = this.outputLayersNodeIndices[i], l = En.nodeKey(a, c); if (!this.containerNodes.has(l)) continue; let u = e[l]; u == null && (u = 0); const d = this.outputLayersTensorIndices[i]; r.push([a.name, u, d]) } return t.outputLayers = r, t } static fromConfig(t, e, s = {}, o = !1) { const r = {}, i = {}; function a(g, b) { g.name in i ? i[g.name].push(b) : i[g.name] = [b] } function c(g, b) { const x = []; let I; for (const y of b) { const C = y[0], w = y[1], k = y[2]; if (I = y[3] == null ? {} : y[3], !(C in r)) { a(g, b); return } const S = r[C]; if (S.inboundNodes.length <= w) { a(g, b); return } const T = S.inboundNodes[w]; x.push(T.outputTensors[k]) } x.length > 0 && g.apply(ze(x), I) } function l(g) { const b = g.name, x = as(g, e.customObjects != null ? e.customObjects : {}); x.setFastWeightInitDuringBuild(o), r[b] = x, g.inboundNodes.forEach(y => { if (!(y instanceof Array)) throw new $(`Corrupted configuration, expected array for nodeData: ${y}`); a(x, y) }) } const u = e.name, d = e.layers; for (const g of d) l(g); for (; !bR(i);)for (const g of d) { const b = r[g.name]; if (b.name in i) { const x = i[b.name]; delete i[b.name]; for (const I of x) c(b, I) } } const h = [], p = [], f = e.inputLayers; for (const g of f) { const b = g[0], x = g[1], I = g[2]; Kn(b in r); const C = r[b].inboundNodes[x].outputTensors; h.push(C[I]) } const m = e.outputLayers; for (const g of m) { const b = g[0], x = g[1], I = g[2]; Kn(b in r); const C = r[b].inboundNodes[x].outputTensors; p.push(C[I]) } return new t({ inputs: h, outputs: p, name: u }) } get stateful() { if (this._stateful) throw new $("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false."); for (const t of this.layers) if (t.stateful) return !0; return !1 } resetStates() { M(() => { this.layers.forEach(t => { t.stateful && t.resetStates() }) }) } }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function G$(n, t, e) { const s = t.length; if (n == null || Array.isArray(n) && n.length === 0) return t.map(o => null); if (s === 1) return Array.isArray(n) && n.length === 1 ? n : typeof n == "object" && t[0] in n ? [n[t[0]]] : [n]; if (Array.isArray(n)) { if (n.length !== s) throw new Error(`Provided ${e} is an array of ${n.length} element(s), but the model has ${s} outputs. Make sure a set of weights is provided for each model output.`); return n } else if (typeof n == "object" && Object.keys(n).length > 0 && typeof n[Object.keys(n)[0]] == "object") { const o = []; return t.forEach(r => { r in n ? o.push(n[r]) : o.push(null) }), o } else throw new Error(`The model has multiple (${s}) outputs, so ${e} must be either an array with ${s} elements or an object with ${t} keys. Provided ${e} not understood: ${JSON.stringify(n)}`) } function A0(n, t) { return G$(n, t, "classWeight") } async function O0(n, t, e, s) { if (t != null || s != null) throw new Error("Support sampleWeight is not implemented yet"); if (e != null) { const o = M(() => { if (n.shape.length === 1) return Qs(n); if (n.shape.length === 2) { if (n.shape[1] > 1) return yi(n, 1); if (n.shape[1] === 1) return D(n, [n.shape[0]]); throw new Error(`Encountered unexpected last-dimension size (${n.shape[1]}) during handling of class weights. The size is expected to be >= 1.`) } else throw new Error(`Unexpected rank of target (y) tensor (${n.rank}) during handling of class weights. The rank is expected to be 1 or 2.`) }), r = Array.from(await o.data()); wt(o); const i = []; return r.forEach(a => { if (e[a] == null) throw new Error(`classWeight must contain all classes in the training data. The class ${a} exists in the data but not in classWeight`); i.push(e[a]) }), on(i, "float32") } else return null } function L$(n, t) { return E(n, t) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const E$ = 32; function P0(n, t) { let e, s; const o = t; e = o.xs, s = o.ys, v(e != null && s != null, () => `A Dataset iterator for fitDataset() is expected to generate objects of the form \`{xs: xVal, ys: yVal}\`, where the two values may be \`tf.Tensor\`, an array of Tensors, or a map of string to Tensor.  The provided Dataset instead generates ${t}`); const r = K0("input", n.inputNames, e), i = K0("output", n.outputNames, s), a = r[0].shape[0]; v(r.length === n.inputs.length, () => `LayersModel has ${n.inputs.length} inputs, but the dataset provides ${r.length} inputs.  (Expected input keys: ${JSON.stringify(n.inputNames)})`), v(i.length === n.outputs.length, () => `LayersModel has ${n.outputs.length} outputs, but the dataset provides ${i.length} outputs.  (Expected output keys: ${JSON.stringify(n.outputNames)})`); for (let c = 0; c < r.length; c++)v(r[c].shape[0] === a, () => `Batch size mismatch: input ${n.inputNames[c]} has ${r[c].shape[0]}; expected  ${a} based on input ${n.inputNames[0]}.`); for (let c = 0; c < i.length; c++)v(i[c].shape[0] === a, () => `Batch size mismatch: output ${n.outputNames[c]} has ${i[c].shape[0]}; expected  ${a} based on input ${n.inputNames[0]}.`); return { xs: r, ys: i } } function K0(n, t, e) { if (e instanceof se) return [e]; if (Array.isArray(e)) return v(e.length === t.length, () => `Received an array of ${e.length} Tensors, but expected ${t.length} to match the ${n} keys ${t}.`), e; { const s = []; for (const o of t) { if (e[o] == null) throw new $(`The feature data generated by the dataset lacks the required ${n} key '${o}'.`); s.push(e[o]) } return s } } function D$(n) { if (n.length === 3) throw new bt("Validation with sample weights is not implemented yet."); return { xs: n[0], ys: n[1] } } async function W$(n, t, e) { const s = e.batchesPerEpoch != null; if (v(n.optimizer != null, () => "You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig)."), v(e != null, () => "For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call."), v(e.epochs != null && e.epochs > 0 && Number.isInteger(e.epochs), () => `For fitDataset(), config.epochs is expected to be a positive integer, but got ${e.epochs}`), v(!s || e.batchesPerEpoch > 0 && Number.isInteger(e.batchesPerEpoch), () => `For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got ${e.batchesPerEpoch}`), v(e.validationSplit == null, () => "`validationSplit` is not supported by `fitDataset()`. Use validationData instead."), n.isTraining) throw new Error("Cannot start training because another fit() call is ongoing."); n.isTraining = !0; try { const o = e.validationData != null; let r, i; if (o) if (Z0(e.validationData)) v(e.validationBatches == null || e.validationBatches > 0 && Number.isInteger(e.validationBatches), () => `For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got ${e.validationBatches}`); else { const g = D$(e.validationData); r = g.xs, i = g.ys } const a = n.makeTrainFunction(), c = n.getDedupedMetricsNames(); let l; o ? l = c.slice().concat(c.map(g => "val_" + g)) : l = c.slice(); const u = $0(e.callbacks, e.yieldEvery), d = e.verbose == null ? 1 : e.verbose, { callbackList: h, history: p } = G0(u, d, e.epochs, null, null, M$(t, e), null, o, l); h.setModel(n), n.history = p, await h.onTrainBegin(), n.stopTraining_ = !1; let f = e.initialEpoch == null ? 0 : e.initialEpoch, m = await t.iterator(); for (; f < e.epochs;) { const g = {}; await h.onEpochBegin(f); let b = 0, x = 0; for (s || (m = await t.iterator()); !s || b < e.batchesPerEpoch;) { const I = await m.next(); if (s && I.done) { console.warn(`You provided \`batchesPerEpoch\` as ${e.batchesPerEpoch}, but your dataset iterator ran out of data after ${b} batches; interrupting training. Make sure that your dataset can generate at least \`batchesPerEpoch * epochs\` batches (in this case, ${e.batchesPerEpoch * e.epochs} batches). You may need to use the repeat() function when building your dataset.`); break } if (I.value != null) { const { xs: y, ys: C } = P0(n, I.value), w = {}; w.batch = x, w.size = y[0].shape[0], await h.onBatchBegin(x, w); const k = []; if (e.classWeight != null) { const R = A0(e.classWeight, n.outputNames); for (let G = 0; G < R.length; ++G)k.push(await O0(C[G], null, R[G])) } const S = y.concat(C).concat(k), T = a(S); wt(S); for (let R = 0; R < c.length; ++R) { const G = c[R], F = T[R]; w[G] = F, tn(F) } await h.onBatchEnd(x, w), N0(w), x++, b++ } if (s ? b >= e.batchesPerEpoch : I.done) { if (o) { let y; Z0(e.validationData) ? y = Bt(await n.evaluateDataset(e.validationData, { batches: e.validationBatches })) : y = Bt(n.evaluate(r, i, { batchSize: e.validationBatchSize == null ? E$ : e.validationBatchSize, verbose: 0 })); for (let C = 0; C < n.metricsNames.length; ++C)g[`val_${n.metricsNames[C]}`] = y[C] } break } if (n.stopTraining_) break } if (await h.onEpochEnd(f, g), f++, n.stopTraining_) break } return await h.onTrainEnd(), await n.history.syncData(), n.history } finally { n.isTraining = !1 } } function M$(n, t) { let e = null; return t.batchesPerEpoch != null ? e = t.batchesPerEpoch : Number.isFinite(n.size) && (e = n.size), e } function Z0(n) { return typeof n.iterator == "function" } function F$(n) { return typeof n.next == "function" } async function V$(n, t, e) { e = e || {}; const s = e.batches != null, o = n.testFunction; let r = []; if (e.verbose > 0) throw new bt("Verbose mode is not implemented yet."); v(!s || e.batches > 0 && Number.isInteger(e.batches), () => `Test loop expects \`batches\` to be a positive integer, but received ${JSON.stringify(e.batches)}`); const i = F$(t) ? t : await t.iterator(); let a = 0, c = 0; for (; !s || c < e.batches;) { const l = await i.next(); if (r = M(() => { if (l.value) { const { xs: u, ys: d } = P0(n, l.value), h = u.concat(d), p = M(() => o(h)); if (wt(h), c === 0) for (let m = 0; m < p.length; ++m)r.push(Gt(0)); const f = h[0].shape[0]; for (let m = 0; m < p.length; ++m) { const g = p[m], b = r[m]; r[m] = M(() => Q(r[m], E(f, g))), c > 0 && wt(b) } wt(p), a += f, ++c } return r }), l.done) { s && console.warn(`Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least \`batches\` batches (in this case, ${e.batches} batches). You may need to use the repeat() function when building your dataset.`); break } } for (let l = 0; l < r.length; ++l) { const u = r[l]; r[l] = dt(r[l], a), wt(u) } return ze(r) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Bh(n) { v(n > 0 && Number.isInteger(n), () => `batchSize is required to be a positive integer, but got ${n}`) } function Pi(n, t, e) { return n == null ? [null] : Array.isArray(n) ? n.map(s => fo(s, t, e - t)) : fo(n, t, e - t) } function Hh(n, t) { return M(() => n == null ? null : Array.isArray(n) ? n.map(e => Hh(e, t)) : a0(n, t.dtype === "int32" ? t : ot(t, "int32"))) } function _h(n, t) { const e = []; let s = 0, o = null; for (; s < n;)o = s + t, o >= n && (o = n), e.push([s, o]), s = o; return e } function B0(n) { const t = []; n instanceof se && (n = [n]); for (let e = 0; e < n.length; ++e) { const s = n[e]; if (s.rank === 1) t.push(Wi(s, 1)); else { if (s.rank === 0) throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar)."); t.push(s) } } return t } function Dn(n, t) { if (n == null) return; const e = []; if (t instanceof se) e.push(t.id); else if (Array.isArray(t)) t.forEach(o => e.push(o.id)); else if (t != null) for (const o in t) { const r = t[o]; e.push(r.id) } const s = []; if (n instanceof se) e.indexOf(n.id) === -1 && s.push(n); else if (Array.isArray(n)) n.forEach(o => { e.indexOf(o.id) === -1 && s.push(o) }); else if (n != null) for (const o in n) { const r = n[o]; e.indexOf(r.id) === -1 && s.push(r) } s.forEach(o => { o.isDisposed || o.dispose() }) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function z$(n) { return n instanceof se } function Uh(n) { return Array.isArray(n) } function H0(n) { return !z$(n) && !Uh(n) } function _0(n, t, e, s = !0, o = "") { if (t == null || t.length === 0) { if (n != null) { let i = !1; if (Uh(n) && n.length > 0) i = !0; else if (H0(n)) { for (const a in n) if (n.hasOwnProperty(a)) { i = !0; break } } else i = !0; if (i) throw new $(`Error when checking model ${o} expected no data, but got ${n}`) } return [] } if (n == null) return t.map(i => null); let r; if (H0(n)) { n = n, r = []; for (const i of t) { if (n[i] == null) throw new $(`No data provided for "${i}". Need data for each key in: ${t}`); r.push(n[i]) } } else if (Uh(n)) { if (n = n, n.length !== t.length) throw new $(`Error when checking model ${o}: the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see ${t.length} Tensor(s), but instead got the following list of Tensor(s): ${n}`); r = n } else { if (n = n, t.length > 1) throw new $(`The model ${o} expects ${t.length} Tensor(s), but only received one Tensor. Found: Tensor with shape ${n.shape}`); r = [n] } if (r = B0(r), e != null) for (let i = 0; i < t.length; ++i) { if (e[i] == null) continue; const a = r[i]; if (a.shape.length !== e[i].length) throw new $(`Error when checking ${o}: expected ${t[i]} to have ${e[i].length} dimension(s). but got array with shape ${a.shape}`); for (let c = 0; c < e[i].length; ++c) { if (c === 0 && !s) continue; const l = a.shape[c], u = e[i][c]; if (u != null && u >= 0 && l !== u) throw new $(`${o} expected a batch of elements where each example has shape [${e[i].slice(1, e[i].length)}] (i.e.,tensor shape [*,${e[i].slice(1, e[i].length)}]) but the ${o} received an input with ${a.shape[0]} examples, each with shape [${a.shape.slice(1, a.shape.length)}] (tensor shape [${a.shape}])`) } } return r } function X$(n, t, e) { const s = ws(n.map(r => r.shape[0])); s.sort(); const o = ws(t.map(r => r.shape[0])); if (o.sort(), s.length > 1) throw new $(`All input Tensors (x) should have the same number of samples. Got array shapes: ${JSON.stringify(n.map(r => r.shape))}`); if (o.length > 1) throw new $(`All target Tensors (y) should have the same number of samples. Got array shapes: ${JSON.stringify(t.map(r => r.shape))}`); if (s.length > 0 && o.length > 0 && !Rt(s, o)) throw new $(`Input Tensors should have the same number of samples as target Tensors. Found ${s[0]} input sample(s) and ${o[0]} target sample(s).`) } function A$(n, t, e) { const s = [Qc, jc, Oi]; for (let o = 0; o < n.length; ++o) { const r = n[o], i = t[o], a = e[o]; if (i != null) { if (i === Oi && r.shape[r.shape.length - 1] === 1) throw new $(`You are passing a target array of shape ${r.shape} while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].`); if (s.indexOf(i) !== -1) { const c = r.shape.slice(1), l = a.slice(1); for (let u = 0; u < c.length; ++u) { const d = c[u], h = l[u]; if (h != null && d !== h) throw new $(`A target Tensor with shape ${r.shape} was passed for an output of shape ${a}, while using a loss function that expects targets to have the same shape as the output.`) } } } } } function U0(n, t, e, s = !0, o = "") { let r; if (Array.isArray(n)) { if (n.length !== t.length) throw new $(`Error when checking model ${o}: the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see ${t.length} Tensor(s), but instead got ${n.length} Tensors(s).`); r = n } else { if (t.length > 1) throw new $(`The model expects ${t.length} ${o} Tensors, but only received one Tensor. Found: array with shape ${JSON.stringify(n.shape)}.`); r = [n] } if (e != null) for (let i = 0; i < t.length; ++i) { if (e[i] == null) continue; const a = r[i]; if (a.shape.length !== e[i].length) throw new $(`Error when checking ${o}: expected ${t[i]} to have ${e[i].length} dimension(s), but got array with shape ${JSON.stringify(a.shape)}`); for (let c = 0; c < e[i].length; ++c) { if (c === 0 && !s) continue; const l = a.shape[c], u = e[i][c]; if (u != null && u !== l) throw new $(`Error when checking ${o}: expected ${t[i]} to have shape ${JSON.stringify(e[i])} but got array with shape ${JSON.stringify(a.shape)}.`) } } } function O$(n, t) { if (n == null || Array.isArray(n) && n.length === 0) return t.map(s => []); let e; if (typeof n == "string" || typeof n == "function") e = [n]; else if (Array.isArray(n) || typeof n == "object") e = n; else throw new TypeError(`Type of metrics argument not understood. Expected an string,function, Array, or Object, found: ${n}`); if (Array.isArray(e)) return t.map(s => e); { const s = []; for (const o of t) { let r = e.hasOwnProperty(o) ? e[o] : []; Array.isArray(r) || (r = [r]), s.push(r) } return s } } const P$ = "layers-model"; class Qo extends En { constructor(t) { super(t), this.isTraining = !1 } summary(t, e, s = console.log) { if (!this.built) throw new $("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data)."); k$(this, t, e, s) } compile(t) { if (t.loss == null && (t.loss = []), this.loss = t.loss, typeof t.optimizer == "string") this.optimizer_ = S$(t.optimizer), this.isOptimizerOwned = !0; else { if (!(t.optimizer instanceof Cs)) throw new $("User-defined optimizer must be an instance of tf.Optimizer."); this.optimizer_ = t.optimizer, this.isOptimizerOwned = !1 } let e = []; if (!Array.isArray(t.loss) && typeof t.loss != "string" && typeof t.loss != "function") { t.loss = t.loss; for (const i in t.loss) if (this.outputNames.indexOf(i) === -1) throw new $(`Unknown entry in loss dictionary: "${i}". Only expected the following keys: ${this.outputNames}`); for (const i of this.outputNames) t.loss[i] == null && console.warn(`Output "${i}" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to ${i} during training`), e.push(Oh(t.loss[i])) } else if (Array.isArray(t.loss)) { if (t.loss.length !== this.outputs.length) throw new $(`When passing an Array as loss, it should have one entry per model output. The model has ${this.outputs.length} output(s), but you passed loss=${t.loss}.`); e = t.loss.map(a => Oh(a)) } else { const i = Oh(t.loss); this.outputs.forEach(a => { e.push(i) }) } this.lossFunctions = e, this.feedOutputNames = [], this.feedOutputShapes = [], this.feedLossFns = []; for (let i = 0; i < this.outputs.length; ++i) { const a = this.internalOutputShapes[i], c = this.outputNames[i]; this.feedOutputNames.push(c), this.feedOutputShapes.push(a), this.feedLossFns.push(this.lossFunctions[i]) } const s = []; this.metrics = t.metrics, this.metricsNames = ["loss"], this.metricsTensors = [], po("loss", () => { for (let i = 0; i < this.outputs.length; ++i) { if (s.indexOf(i) !== -1) continue; const a = this.lossFunctions[i]; this.outputs.length > 1 && (this.metricsTensors.push([a, i]), this.metricsNames.push(this.outputNames[i] + "_loss")) } }); const o = O$(t.metrics, this.outputNames), r = (i, a, c) => { this.outputNames.length > 1 && (a = this.outputNames[i] + "_" + a), this.metricsNames.push(a), this.metricsTensors.push([c, i]) }; po("metric", () => { for (let i = 0; i < this.outputs.length; ++i) { if (s.indexOf(i) !== -1) continue; const a = o[i]; (l => { const u = ""; let d, h, p; for (const f of l) { if (typeof f == "string" && ["accuracy", "acc", "crossentropy", "ce"].indexOf(f) !== -1) { const g = this.internalOutputShapes[i]; g[g.length - 1] === 1 || this.lossFunctions[i] === jc ? ["accuracy", "acc"].indexOf(f) !== -1 ? h = E0 : ["crossentropy", "ce"].indexOf(f) !== -1 && (h = f$) : this.lossFunctions[i] === Jc ? ["accuracy", "acc"].indexOf(f) !== -1 ? h = m$ : ["crossentropy", "ce"].indexOf(f) !== -1 && (h = M0) : ["accuracy", "acc"].indexOf(f) !== -1 ? h = D0 : ["crossentropy", "ce"].indexOf(f) !== -1 && (h = W0); let b;["accuracy", "acc"].indexOf(f) !== -1 ? b = "acc" : ["crossentropy", "ce"].indexOf(f) !== -1 && (b = "ce"), p = h, d = u + b } else p = v$(f), d = u + el(f); let m; po(d, () => { m = p }), r(i, d, m) } })(a) } }), this.collectedTrainableWeights = this.trainableWeights } checkTrainableWeightsConsistency() { this.collectedTrainableWeights != null && this.trainableWeights.length !== this.collectedTrainableWeights.length && console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?") } evaluate(t, e, s = {}) { const o = s.batchSize == null ? 32 : s.batchSize; Bh(o); const r = !0, i = this.standardizeUserDataXY(t, e, r, o); try { const a = i[0].concat(i[1]); this.makeTestFunction(); const c = this.testFunction, l = this.testLoop(c, a, o, s.verbose, s.steps); return ze(l) } finally { Dn(i[0], t), Dn(i[1], e) } } async evaluateDataset(t, e) { return this.makeTestFunction(), V$(this, t, e) } checkNumSamples(t, e, s, o = "steps") { let r; if (s != null) { if (r = null, e != null) throw new $(`If ${o} is set, batchSize must be null or undefined.Got batchSize = ${e}`) } else if (t != null) Array.isArray(t) ? r = t[0].shape[0] : r = t.shape[0]; else throw new $(`Either the input data should have a defined shape, or ${o} shoud be specified.`); return r } execute(t, e) { if (Array.isArray(e) && e.length === 0) throw new $("`outputs` is an empty Array, which is not allowed."); const s = Array.isArray(e), o = s ? e : [e], r = this.retrieveSymbolicTensors(o), i = new ks; if (t instanceof se && (t = [t]), Array.isArray(t)) { if (t.length !== this.inputs.length) throw new $(`The number of inputs provided (${t.length}) does not match the number of inputs of this model (${this.inputs.length}).`); for (let c = 0; c < this.inputs.length; ++c)i.add(this.inputs[c], t[c]) } else for (const c of this.inputs) { const l = t[c.name]; if (l == null) throw new $(`No value is provided for the model's input ${c.name}`); i.add(c, l) } const a = zi(r, i); return s ? a : a[0] } retrieveSymbolicTensors(t) { const e = lo(null, t.length); let s = t.length; for (const o of this.layers) { const r = Array.isArray(o.output) ? o.output : [o.output], i = r.map(a => a.name); for (let a = 0; a < t.length; ++a) { const c = i.indexOf(t[a]); if (c !== -1 && (e[a] = r[c], s--), s === 0) break } if (s === 0) break } if (s > 0) { const o = []; throw e.forEach((r, i) => { r == null && o.push(t[i]) }), new $(`Cannot find SymbolicTensors for output name(s): ${JSON.stringify(o)}`) } return e } predictLoop(t, e = 32, s = !1) { return M(() => { const o = this.checkNumSamples(t); if (s) throw new bt("Verbose predictLoop() is not implemented yet."); const r = _h(o, e), i = this.outputs.map(a => []); for (let a = 0; a < r.length; ++a)M(() => { const l = r[a][0], u = r[a][1], d = Pi(t, l, u), h = []; if (Array.isArray(d)) for (let f = 0; f < d.length; ++f)h.push({ key: this.inputs[f], value: d[f] }); else h.push({ key: this.inputs[0], value: d }); const p = new ks(h); return zi(this.outputs, p) }).forEach((l, u) => i[u].push(l)); return ze(i.map(a => Ve(a, 0))) }) } predict(t, e = {}) { const s = B0(t); U0(s, this.inputNames, this.feedInputShapes, !1); try { const o = e.batchSize == null ? 32 : e.batchSize; return Bh(o), this.predictLoop(s, o) } finally { Dn(s, t) } } predictOnBatch(t) { U0(t, this.inputNames, this.feedInputShapes, !0); const e = (Array.isArray(t) ? t[0] : t).shape[0]; return this.predictLoop(t, e) } standardizeUserDataXY(t, e, s = !0, o) { if (this.optimizer_ == null) throw new mn("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs)."); const r = []; for (let i = 0; i < this.feedOutputShapes.length; ++i) { const a = this.feedOutputShapes[i]; this.feedLossFns[i] === Jc ? r.push(a.slice(0, a.length - 1).concat([1])) : r.push(a) } if (t = _0(t, this.feedInputNames, this.feedInputShapes, !1, "input"), e = _0(e, this.feedOutputNames, r, !1, "target"), X$(t, e), A$(e, this.feedLossFns, this.feedOutputShapes), this.stateful && o != null && o > 0 && t[0].shape[0] % o !== 0) throw new $(`In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size ${o}. Found: ${t[0].shape[0]} sample(s).`); return [t, e] } async standardizeUserData(t, e, s, o, r = !0, i) { const [a, c] = this.standardizeUserDataXY(t, e, r, i); if (s != null) throw new Error("sample weight is not supported yet."); let l = null; if (o != null) { const u = A0(o, this.outputNames); l = []; for (let d = 0; d < u.length; ++d)l.push(await O0(c[d], null, u[d])) } return [a, c, l] } testLoop(t, e, s, o = 0, r) { return M(() => { const i = this.checkNumSamples(e, s, r, "steps"), a = []; if (o > 0) throw new bt("Verbose mode is not implemented yet."); if (r != null) throw new bt("steps mode in testLoop() is not implemented yet"); { const c = _h(i, s), l = on($n(0, i)); for (let u = 0; u < c.length; ++u) { const d = c[u][0], h = c[u][1], p = fo(l, d, h - d), f = Hh(e, p), m = t(f); if (u === 0) for (let g = 0; g < m.length; ++g)a.push(Gt(0)); for (let g = 0; g < m.length; ++g) { const b = m[g]; a[g] = Q(a[g], E(h - d, b)) } } for (let u = 0; u < a.length; ++u)a[u] = dt(a[u], i) } return a }) } getDedupedMetricsNames() { const t = this.metricsNames, e = []; for (let s = 0; s < t.length; ++s) { const o = t[s]; let r = o; if (Jg(t, o) > 1) { const i = Jg(t.slice(0, s), o); r += `_${i}` } e.push(r) } return e } makeTrainFunction() { return t => { const e = [], s = t.slice(0, this.inputs.length), o = t.slice(this.inputs.length, this.inputs.length + this.outputs.length), r = t.slice(this.inputs.length + this.outputs.length, this.inputs.length + this.outputs.length * 2), i = [], a = () => { const d = []; for (let m = 0; m < this.inputs.length; ++m)d.push({ key: this.inputs[m], value: s[m] }); const h = new ks(d), p = zi(this.outputs, h, { training: !0 }); let f; for (let m = 0; m < this.lossFunctions.length; ++m) { const g = this.lossFunctions[m]; let b = g(o[m], p[m]); r[m] != null && (b = L$(b, r[m])); const x = ie(b); e.push(x), m === 0 ? f = b : f = Q(f, b) } for (let m = 0; m < this.metricsTensors.length; ++m) { let g; if (this.outputs.length > 1 && m < this.outputs.length) g = e[m]; else { const b = this.metricsTensors[m][0], x = this.metricsTensors[m][1]; g = ie(b(o[x], p[x])) } tn(g), i.push(g) } return f = ie(f), this.calculateLosses().forEach(m => { f = Q(f, m) }), f }, c = this.collectedTrainableWeights.map(d => d.read()), l = !0; return [this.optimizer_.minimize(a, l, c)].concat(i) } } makeTestFunction() { this.testFunction = t => M(() => { const e = []; let s; const o = t.slice(0, this.inputs.length), r = t.slice(this.inputs.length, this.inputs.length + this.outputs.length), i = []; for (let l = 0; l < this.inputs.length; ++l)i.push({ key: this.inputs[l], value: o[l] }); const a = new ks(i), c = zi(this.outputs, a); for (let l = 0; l < this.lossFunctions.length; ++l) { const u = this.lossFunctions[l], d = ie(u(r[l], c[l])); l === 0 ? s = d : s = Q(s, d), e.push(s) } for (let l = 0; l < this.metricsTensors.length; ++l) { const u = this.metricsTensors[l][0], d = this.metricsTensors[l][1], h = ie(u(r[d], c[d])); e.push(h) } return e }) } async fit(t, e, s = {}) { if (this.isTraining) throw new Error("Cannot start training because another fit() call is ongoing."); this.isTraining = !0; let o, r, i, a, c, l, u, d, h; try { const p = s.batchSize == null ? 32 : s.batchSize; Bh(p); const f = !1, m = await this.standardizeUserData(t, e, s.sampleWeight, s.classWeight, f, p); o = m[0], r = m[1], h = m[2]; let g = !1, b; if (s.validationData != null && s.validationData.length > 0) { if (g = !0, s.validationData.length === 2) c = s.validationData[0], l = s.validationData[1]; else throw s.validationData.length === 3 ? new bt("validationData including sample weights is not supported yet.") : new $(`When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; ${s.validationData} is invalid.`); const T = !0, R = await this.standardizeUserData(c, l, null, null, T, p); u = R[0], d = R[1], b = u.concat(d) } else if (s.validationSplit != null && s.validationSplit > 0 && s.validationSplit < 1) { g = !0; const T = Math.floor(o[0].shape[0] * (1 - s.validationSplit)), R = o[0].shape[0]; u = Pi(o, T, R), i = o, o = Pi(o, 0, T), d = Pi(r, T, R), a = r, r = Pi(r, 0, T), b = u.concat(d) } else s.validationSteps != null && (g = !0); const x = o.concat(r).concat(h); this.checkTrainableWeightsConsistency(); const I = this.makeTrainFunction(), y = this.getDedupedMetricsNames(); let C, w; g ? (this.makeTestFunction(), C = this.testFunction, w = y.slice().concat(y.map(T => "val_" + T))) : (C = null, b = [], w = y.slice()); const k = $0(s.callbacks, s.yieldEvery); return await this.fitLoop(I, x, y, p, s.epochs, s.verbose, k, C, b, s.shuffle, w, s.initialEpoch, null, null) } finally { this.isTraining = !1, Dn(o, t), Dn(r, e), Dn(i, t), Dn(a, e), Dn(u, c), Dn(d, l), h != null && wt(h) } } async fitLoop(t, e, s, o, r, i, a, c, l, u, d, h, p, f) { o == null && (o = 32), r == null && (r = 1), u == null && (u = !0), h == null && (h = 0); let m = !1; if (c != null && l != null && (m = !0), f != null && (m = !0, p == null)) throw new $("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set."); const g = this.checkNumSamples(e, o, p, "steps_per_epoch"); let b; g != null && (b = $n(0, g)), i == null && (i = 1); const { callbackList: x, history: I } = G0(a, i, r, h, g, p, o, m, d); x.setModel(this), this.history = I, await x.onTrainBegin(), this.stopTraining_ = !1; for (let y = h; y < r; ++y) { await x.onEpochBegin(y); const C = {}; if (p != null) throw new bt("stepsPerEpoch mode is not implemented yet."); { if (u === "batch") throw new bt("batch shuffling is not implemneted yet"); u && FI(b); const w = on(b), k = _h(g, o); for (let S = 0; S < k.length; ++S) { const T = {}; if (await x.onBatchBegin(S, T), M(() => { const R = k[S][0], G = k[S][1], F = fo(w, R, G - R); T.batch = S, T.size = G - R; const V = Hh(e, F), z = t(V); for (let X = 0; X < s.length; ++X) { const O = s[X], B = z[X]; T[O] = B, tn(B) } if (S === k.length - 1 && m) { const X = this.testLoop(c, l, o); for (let O = 0; O < s.length; ++O) { const B = s[O], K = X[O]; tn(K), C["val_" + B] = K } } }), await x.onBatchEnd(S, T), N0(T), this.stopTraining_) break } w.dispose() } if (await x.onEpochEnd(y, C), this.stopTraining_) break } return await x.onTrainEnd(), await this.history.syncData(), this.history } async fitDataset(t, e) { return W$(this, t, e) } async trainOnBatch(t, e) { const s = await this.standardizeUserData(t, e), o = s[0], r = s[1], a = this.makeTrainFunction()(o.concat(r)), c = []; for (const l of a) { const u = await l.data(); c.push(u[0]) } return wt(a), Dn(s[0], t), Dn(s[1], e), ze(c) } getNamedWeights(t) { const e = [], s = t != null && t.trainableOnly, o = s ? this.trainableWeights : this.weights, r = this.getWeights(s); for (let i = 0; i < o.length; ++i)s && !o[i].trainable || e.push({ name: o[i].originalName, tensor: r[i] }); return e } set stopTraining(t) { this.stopTraining_ = t } get stopTraining() { return this.stopTraining_ } get optimizer() { return this.optimizer_ } set optimizer(t) { this.optimizer_ !== t && (this.optimizer_ = t, this.isOptimizerOwned = !1) } dispose() { const t = super.dispose(); if (t.refCountAfterDispose === 0 && this.optimizer != null && this.isOptimizerOwned) { const e = vc().numTensors; this.optimizer_.dispose(), t.numDisposedVariables += e - vc().numTensors } return t } getLossIdentifiers() { let t; if (typeof this.loss == "string") t = is(this.loss); else if (Array.isArray(this.loss)) { for (const e of this.loss) if (typeof e != "string") throw new Error("Serialization of non-string loss is not supported."); t = this.loss.map(e => is(e)) } else { const e = Object.keys(this.loss); t = {}; const s = this.loss; for (const o of e) if (typeof s[o] == "string") t[o] = is(s[o]); else throw new Error("Serialization of non-string loss is not supported.") } return t } getMetricIdentifiers() { if (typeof this.metrics == "string" || typeof this.metrics == "function") return [is(el(this.metrics))]; if (Array.isArray(this.metrics)) return this.metrics.map(t => is(el(t))); { const t = {}; for (const e in this.metrics) t[e] = is(el(this.metrics[e])); return t } } getTrainingConfig() { return { loss: this.getLossIdentifiers(), metrics: this.getMetricIdentifiers(), optimizer_config: { class_name: this.optimizer.getClassName(), config: this.optimizer.getConfig() } } } loadTrainingConfig(t) { if (t.weighted_metrics != null) throw new Error("Loading weight_metrics is not supported yet."); if (t.loss_weights != null) throw new Error("Loading loss_weights is not supported yet."); if (t.sample_weight_mode != null) throw new Error("Loading sample_weight_mode is not supported yet."); const e = Kh(t.optimizer_config), s = as(e); let o; if (typeof t.loss == "string") o = uo(t.loss); else if (Array.isArray(t.loss)) o = t.loss.map(i => uo(i)); else if (t.loss != null) { o = {}; for (const i in t.loss) o[i] = uo(t.loss[i]) } let r; if (Array.isArray(t.metrics)) r = t.metrics.map(i => uo(i)); else if (t.metrics != null) { r = {}; for (const i in t.metrics) r[i] = uo(t.metrics[i]) } this.compile({ loss: o, metrics: r, optimizer: s }) } async save(t, e) { if (typeof t == "string") { const l = $C(t); if (l.length === 0) throw new $(`Cannot find any save handlers for URL '${t}'`); if (l.length > 1) throw new $(`Found more than one (${l.length}) save handlers for URL '${t}'`); t = l[0] } if (t.save == null) throw new $("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined."); const s = await cm(this.getNamedWeights(e)), o = !1, r = null, a = { modelTopology: this.toJSON(r, o), format: P$, generatedBy: `TensorFlow.js tfjs-layers v${X0}`, convertedBy: null }; if ((e == null ? !1 : e.includeOptimizer) && this.optimizer != null) { a.trainingConfig = this.getTrainingConfig(); const l = "optimizer", { data: u, specs: d } = await cm(await this.optimizer.getWeights(), l); s.specs.push(...d), s.data = RC([s.data, u]) } return this.userDefinedMetadata != null && (V0(this.userDefinedMetadata, this.name, !0), a.userDefinedMetadata = this.userDefinedMetadata), a.weightData = s.data, a.weightSpecs = s.specs, t.save(a) } setUserDefinedMetadata(t) { V0(t, this.name), this.userDefinedMetadata = t } getUserDefinedMetadata() { return this.userDefinedMetadata } } Qo.className = "Model", _(Qo); class Y0 extends Qo { } Y0.className = "Functional", _(Y0);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Ki extends Qo { constructor(t) { if (super({ inputs: [], outputs: [] }), t = t || {}, this.trainable = !0, this.built = !1, this.name = t.name != null ? t.name : Oc("sequential_"), t.layers != null) for (const e of t.layers) this.add(e) } checkShape(t) { if (t.inboundNodes[0].outputTensors[0].shape.some(s => s < 0)) throw new $(`Negative dimension size caused by adding layer ${t.name} with input shape [${t.inboundNodes[0].inputTensors[0].shape}]`) } add(t) { const e = t instanceof Ki || t instanceof Qo; let s; if (e) { if (s = t, s.outputs.length !== 1) throw new $("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API."); if (s.inputs.length !== 1) throw new $("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.") } if (this.outputs.length === 0) { if (t.inboundNodes.length === 0) { if (t.batchInputShape == null) throw new $("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument."); const o = HR({ batchShape: t.batchInputShape, dtype: t.dtype, name: t.name + "_input" }); t.apply(o) } if (e) this.outputs = s.outputs, this.inputs = s.inputs; else { if (t.inboundNodes.length !== 1) throw new $(`A layer added to a Sequential model must not already be connected somewhere else. LayersModel received layer ${t.name} which has ${t.inboundNodes.length} pre-existing inbound connections.`); if (t.inboundNodes[0].outputTensors.length !== 1) throw new $("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API."); this.checkShape(t), this.outputs = [t.inboundNodes[0].outputTensors[0]], this.inputs = y0(this.outputs[0]) } this.inboundNodes = [], new Hc({ outboundLayer: this, inboundLayers: [], nodeIndices: [], tensorIndices: [], inputTensors: this.inputs, outputTensors: this.outputs, inputMasks: lo(null, this.inputs.length), outputMasks: [null], inputShapes: this.inputs.map(o => o.shape), outputShapes: this.outputs[0].shape }) } else { const o = t.apply(this.outputs[0]); if (Array.isArray(o)) throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API."); this.checkShape(t), this.outputs = [o], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape] } this.layers.push(t), this.built = !1 } pop() { if (this.layers.length === 0) throw new TypeError("There are no layers in the model."); if (this.layers.pop(), this.layers.length === 0) this.outputs = [], this.inboundNodes = [], this.outboundNodes = []; else { const t = this.layers.length - 1; this.layers[t].outboundNodes = [], this.outputs = [this.layers[t].output], this.inboundNodes[0].outputTensors = this.outputs, this.inboundNodes[0].outputShapes = [this.outputs[0].shape] } } call(t, e) { return this.model == null && this.build(), this.model.call(t, e) } build(t) { if (Nt(t), this.inputs.length === 0 || this.outputs.length === 0) throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first."); this.model = new Qo({ inputs: this.inputs, outputs: this.outputs[0], name: this.name + "_model" }), this.model.trainable = this.trainable, this.supportsMasking = this.model.supportsMasking, this.inputLayers = this.model.inputLayers, this.inputLayersNodeIndices = this.model.inputLayersNodeIndices, this.inputLayersTensorIndices = this.model.inputLayersTensorIndices, this.outputLayers = this.model.outputLayers, this.outputLayersNodeIndices = this.model.outputLayersNodeIndices, this.outputLayersTensorIndices = this.model.outputLayersTensorIndices, this.nodesByDepth = this.model.nodesByDepth, this.containerNodes = this.model.containerNodes, this.outputNames = this.model.outputNames, this.inputNames = this.model.inputNames, this.built = !0 } countParams() { return this.built || this.build(), super.countParams() } summary(t, e, s = console.log) { this.built || this.build(), super.summary(t, e, s) } setWeights(t) { this.model == null && this.build(), this.model.setWeights(t) } evaluate(t, e, s = {}) { if (!this.built) throw new mn("The model needs to be compiled before being used."); return this.model.evaluate(t, e, s) } async evaluateDataset(t, e) { if (!this.built) throw new mn("The model needs to be compiled before being used."); return this.model.evaluateDataset(t, e) } predict(t, e = {}) { return this.model == null && this.build(), this.model.predict(t, e) } predictOnBatch(t) { return this.model == null && this.build(), this.model.predictOnBatch(t) } compile(t) { this.build(), this.model.compile(t), this.optimizer_ = this.model.optimizer, this.isOptimizerOwned = this.model.isOptimizerOwned, this.loss = this.model.loss, this.metrics = this.model.metrics, this.metricsTensors = this.model.metricsTensors, this.metricsNames = this.model.metricsNames } get optimizer() { return this.model == null ? void 0 : this.model.optimizer } set optimizer(t) { this.model.optimizer = t } async fit(t, e, s = {}) { if (!this.built) throw new mn("The model needs to be compiled before being used."); return this.model.fit(t, e, s) } async fitDataset(t, e) { if (!this.built) throw new mn("The model needs to be compiled before being used."); return this.model.fitDataset(t, e) } async trainOnBatch(t, e) { return this.model.trainOnBatch(t, e) } static fromConfig(t, e, s = {}, o = !1) { let r, i = {}; if (e instanceof Array) { if (e[0].className == null || e[0].className === "Merge") throw new $("Legacy serialization format not supported yet."); r = e } else v(e.layers != null, () => "When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field."), r = e.layers, delete e.layers, i = e; const a = new t(i); if (!(a instanceof Ki)) throw new bt(`Sequential.fromConfig called on non-Sequential input: ${a}`); for (const c of r) { const u = as(c, void 0, o); o && u.setFastWeightInitDuringBuild(!0), a.add(u) } return a } set stopTraining(t) { if (this.model == null) throw new $("Cannot set the stopTraining property of a sequential model before it is compiled."); this.model.stopTraining = t } get stopTraining() { if (this.model == null) throw new $("Cannot get the stopTraining property of a sequential model before it is compiled."); return this.model.stopTraining } getConfig() { const t = []; for (const e of this.layers) { const s = {}; s.className = e.getClassName(), s.config = e.getConfig(), t.push(s) } return { name: this.name, layers: t } } } Ki.className = "Sequential", _(Ki);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */let Xe = class extends Ho { getConfig() { return {} } }; class Q0 extends Xe { apply(t, e = 1) { return ER(t, e) } } Q0.className = "elu", _(Q0); class J0 extends Xe { apply(t) { return Am(t) } } J0.className = "selu", _(J0); class j0 extends Xe { apply(t) { return so(t) } } j0.className = "relu", _(j0); class q0 extends Xe { apply(t) { return M(() => xd(6, so(t))) } } q0.className = "relu6", _(q0); class tb extends Xe { apply(t) { return t } } tb.className = "linear", _(tb); class eb extends Xe { apply(t) { return Ao(t) } } eb.className = "sigmoid", _(eb); class nb extends Xe { apply(t) { return WR(t) } } nb.className = "hardSigmoid", _(nb); class sb extends Xe { apply(t) { return Si(t) } } sb.className = "softplus", _(sb); class ob extends Xe { apply(t) { return DR(t) } } ob.className = "softsign", _(ob); class rb extends Xe { apply(t) { return id(t) } } rb.className = "tanh", _(rb); let Yh = class extends Xe { apply(t, e = -1) { return Ed(t, e) } }; Yh.className = "softmax", _(Yh); class ib extends Xe { apply(t, e = -1) { return Em(t, e) } } ib.className = "logSoftmax", _(ib); class ab extends Xe { apply(t, e = 1) { return M(() => E(Ao(E(t, e)), t)) } } ab.className = "swish", _(ab); class cb extends Xe { apply(t) { return M(() => E(t, id(Si(t)))) } } cb.className = "mish", _(cb); function Ts(n) { return n.getClassName() } function Qh(n, t = {}) { return Ei(n, fn.getMap().classNameMap, t, "activation") } function Ns(n) { if (n == null) { const t = {}; return t.className = "linear", t.config = {}, Qh(t) } if (typeof n == "string") { const t = {}; return t.className = n, t.config = {}, Qh(t) } else return n instanceof Xe ? n : Qh(n) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function K$(n) { if (n != null && typeof n != "object") throw new Error(`Argument to L1L2 regularizer's constructor is expected to be an object, but received: ${n}`) } class lb extends Ho { } class ub extends lb { constructor(t) { super(), K$(t), this.l1 = t == null || t.l1 == null ? .01 : t.l1, this.l2 = t == null || t.l2 == null ? .01 : t.l2, this.hasL1 = this.l1 !== 0, this.hasL2 = this.l2 !== 0 } apply(t) { return M(() => { let e = me([1]); return this.hasL1 && (e = Q(e, ut(E(this.l1, $e(t))))), this.hasL2 && (e = Q(e, ut(E(this.l2, Mi(t))))), D(e, []) }) } getConfig() { return { l1: this.l1, l2: this.l2 } } static fromConfig(t, e) { return new t({ l1: e.l1, l2: e.l2 }) } } ub.className = "L1L2", _(ub); const db = { l1l2: "L1L2" }; function Wt(n) { return Ih(n) } function hb(n, t = {}) { return Ei(n, fn.getMap().classNameMap, t, "regularizer") } function _t(n) { if (n == null) return null; if (typeof n == "string") { const e = { className: n in db ? db[n] : n, config: {} }; return hb(e) } else return n instanceof lb ? n : hb(n) }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class pb extends vt { constructor(t) { super(t ?? {}), this.supportsMasking = !0, t != null && (this.maxValue = t.maxValue) } call(t, e) { t = mt(t); let s = so(t); return this.maxValue != null && (s = en(s, 0, this.maxValue)), s } computeOutputShape(t) { return t } getConfig() { const t = { maxValue: this.maxValue }, e = super.getConfig(); return Object.assign(t, e), t } } pb.className = "ReLU", _(pb); class fb extends vt { constructor(t) { super(t ?? {}), this.DEFAULT_ALPHA = .3, t == null && (t = {}), this.alpha = t.alpha == null ? this.DEFAULT_ALPHA : t.alpha } call(t, e) { const s = mt(t); return md(s, this.alpha) } computeOutputShape(t) { return t } getConfig() { const t = { alpha: this.alpha }, e = super.getConfig(); return Object.assign(t, e), t } } fb.className = "LeakyReLU", _(fb); class mb extends vt { constructor(t) { if (super(t ?? {}), this.DEFAULT_ALPHA_INITIALIZER = "zeros", t == null && (t = {}), this.supportsMasking = !0, this.alphaInitializer = Ht(t.alphaInitializer || this.DEFAULT_ALPHA_INITIALIZER), this.alphaRegularizer = _t(t.alphaRegularizer), this.alphaConstraint = he(t.alphaConstraint), t.sharedAxes == null) this.sharedAxes = null; else if (Array.isArray(t.sharedAxes)) this.sharedAxes = t.sharedAxes; else if (typeof t.sharedAxes == "number") this.sharedAxes = [t.sharedAxes]; else throw new $(`Expected sharedAxes to be a number or an array of numbers, but got ${t.sharedAxes}`) } build(t) { t = Nt(t); const e = t.slice(1); if (this.sharedAxes != null) for (const o of this.sharedAxes) e[o - 1] = 1; this.alpha = this.addWeight("alpha", e, "float32", this.alphaInitializer, this.alphaRegularizer, !0, this.alphaConstraint); const s = {}; if (this.sharedAxes != null) for (let o = 1; o < t.length; ++o)s[o] = t[o]; this.inputSpec = [new ue({ ndim: t.length, axes: s })], this.built = !0 } call(t, e) { return t = mt(t), wd(t, this.alpha.read()) } getConfig() { const t = { alphaInitializer: Qt(this.alphaInitializer), alphaRegularizer: Wt(this.alphaRegularizer), alphaConstraint: de(this.alphaConstraint), sharedAxes: this.sharedAxes }, e = super.getConfig(); return Object.assign(t, e), t } } mb.className = "PReLU", _(mb); let gb = class extends vt { constructor(t) { if (super(t ?? {}), this.DEFAULT_ALPHA = 1, t == null && (t = {}), t.alpha != null && t.alpha !== this.DEFAULT_ALPHA) throw new bt(`Non-default alpha value (${t.alpha}) is not supported by the ELU layer yet.`); this.alpha = t.alpha == null ? this.DEFAULT_ALPHA : t.alpha } call(t, e) { const s = mt(t); return Tc(s) } computeOutputShape(t) { return t } getConfig() { const t = { alpha: this.alpha }, e = super.getConfig(); return Object.assign(t, e), t } }; gb.className = "ELU", _(gb); class bb extends vt { constructor(t) { super(t ?? {}), this.DEFAULT_THETA = 1, t == null && (t = {}), this.theta = t.theta == null ? this.DEFAULT_THETA : t.theta } call(t, e) { const s = mt(t); return E(s, ot(nn(s, this.theta), "float32")) } computeOutputShape(t) { return t } getConfig() { const t = { theta: this.theta }, e = super.getConfig(); return Object.assign(t, e), t } } bb.className = "ThresholdedReLU", _(bb); class xb extends vt { constructor(t) { super(t ?? {}), this.DEFAULT_AXIS = 1, t == null && (t = {}), this.softmax = new Yh().apply, this.axis = t.axis == null ? this.DEFAULT_AXIS : t.axis } call(t, e) { const s = mt(t); return this.softmax(s, this.axis) } computeOutputShape(t) { return t } getConfig() { const t = { axis: this.axis }, e = super.getConfig(); return Object.assign(t, e), t } } xb.className = "Softmax", _(xb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Jo(n, t, e) { if (typeof n == "number") return lo(n, t); if (n.length !== t) throw new $(`The ${e} argument must be an integer or tuple of ${t} integers. Received: ${n.length} elements.`); for (let s = 0; s < t; ++s) { const o = n[s]; if (!RR(o)) throw new $(`The ${e} argument must be an integer or tuple of ${t} integers. Received: ${JSON.stringify(n)} including a non-integer number ${o}`) } return n } function Wn(n, t, e, s, o = 1) { if (n == null) return n; const r = t + (t - 1) * (o - 1); let i; return e === "same" ? i = n : i = n - r + 1, Math.floor((i + s - 1) / s) } function _n(n, t, e, s) { if (n == null) return null; if (s === "valid") n = n * t + Ss([e - t, 0]); else if (s === "same") n = n * t; else throw new $(`Unsupport padding mode: ${s}.`); return n }/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Jh(n, t) { return M(() => (ee(t), t === "channelsFirst" ? St(n, [0, 2, 3, 1]) : n)) } function yb(n, t) { return M(() => (ee(t), t === "channelsFirst" ? St(n, [0, 2, 3, 4, 1]) : n)) } function Z$(n, t, e, s = 1, o = "valid", r, i = 1) { return M(() => { if (r == null && (r = Gn()), ee(r), n.shape.length !== 3) throw new $(`The input of a conv1dWithBias operation should be 3, but is ${n.shape.length} instead.`); if (t.shape.length !== 3) throw new $(`The kernel for a conv1dWithBias operation should be 3, but is ${t.shape.length} instead`); if (e != null && e.shape.length !== 1) throw new $(`The bias for a conv1dWithBias operation should be 1, but is ${t.shape.length} instead`); if (r === "channelsFirst" && (n = St(n, [0, 2, 1])), o === "causal") throw new bt("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet."); let a = Cm(n, t, s, o === "same" ? "same" : "valid", "NWC", i); return e != null && (a = Ln(a, e)), a }) } function Ib(n, t, e, s = [1, 1], o = "valid", r, i, a = null) { return M(() => { if (r == null && (r = Gn()), ee(r), n.rank !== 3 && n.rank !== 4) throw new $(`conv2dWithBiasActivation expects input to be of rank 3 or 4, but received ${n.rank}.`); if (t.rank !== 3 && t.rank !== 4) throw new $(`conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received ${n.rank}.`); let c = Jh(n, r); if (o === "causal") throw new bt("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet."); return c = rk({ x: c, filter: t, strides: s, pad: o === "same" ? "same" : "valid", dilations: i, dataFormat: "NHWC", bias: e, activation: a }), r === "channelsFirst" && (c = St(c, [0, 3, 1, 2])), c }) } function B$(n, t, e, s = [1, 1, 1], o = "valid", r, i) { return M(() => { if (r == null && (r = Gn()), ee(r), n.rank !== 4 && n.rank !== 5) throw new $(`conv3dWithBias expects input to be of rank 4 or 5, but received ${n.rank}.`); if (t.rank !== 4 && t.rank !== 5) throw new $(`conv3dWithBias expects kernel to be of rank 4 or 5, but received ${n.rank}.`); let a = yb(n, r); if (o === "causal") throw new bt("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet."); return a = o2(a, t, s, o === "same" ? "same" : "valid", "NDHWC", i), e != null && (a = Ln(a, e)), r === "channelsFirst" && (a = St(a, [0, 4, 1, 2, 3])), a }) } class sl extends vt { constructor(t, e) { if (super(e), this.bias = null, this.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", this.DEFAULT_BIAS_INITIALIZER = "zeros", sl.verifyArgs(e), this.rank = t, ge(this.rank, "rank"), this.rank !== 1 && this.rank !== 2 && this.rank !== 3) throw new bt(`Convolution layer for rank other than 1, 2, or 3 (${this.rank}) is not implemented yet.`); if (this.kernelSize = Jo(e.kernelSize, t, "kernelSize"), this.strides = Jo(e.strides == null ? 1 : e.strides, t, "strides"), this.padding = e.padding == null ? "valid" : e.padding, rn(this.padding), this.dataFormat = e.dataFormat == null ? "channelsLast" : e.dataFormat, ee(this.dataFormat), this.activation = Ns(e.activation), this.useBias = e.useBias == null ? !0 : e.useBias, this.biasInitializer = Ht(e.biasInitializer || this.DEFAULT_BIAS_INITIALIZER), this.biasConstraint = he(e.biasConstraint), this.biasRegularizer = _t(e.biasRegularizer), this.activityRegularizer = _t(e.activityRegularizer), this.dilationRate = Jo(e.dilationRate == null ? 1 : e.dilationRate, t, "dilationRate"), this.rank === 1 && Array.isArray(this.dilationRate) && this.dilationRate.length !== 1) throw new $(`dilationRate must be a number or an array of a single number for 1D convolution, but received ${JSON.stringify(this.dilationRate)}`); if (this.rank === 2) { if (typeof this.dilationRate == "number") this.dilationRate = [this.dilationRate, this.dilationRate]; else if (this.dilationRate.length !== 2) throw new $(`dilationRate must be a number or array of two numbers for 2D convolution, but received ${JSON.stringify(this.dilationRate)}`) } else if (this.rank === 3) { if (typeof this.dilationRate == "number") this.dilationRate = [this.dilationRate, this.dilationRate, this.dilationRate]; else if (this.dilationRate.length !== 3) throw new $(`dilationRate must be a number or array of three numbers for 3D convolution, but received ${JSON.stringify(this.dilationRate)}`) } } static verifyArgs(t) { if (Kn("kernelSize" in t, "required key 'kernelSize' not in config"), typeof t.kernelSize != "number" && !wh(t.kernelSize, "number", 1, 3)) throw new $(`BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received ${JSON.stringify(t.kernelSize)}.`) } getConfig() { const t = { kernelSize: this.kernelSize, strides: this.strides, padding: this.padding, dataFormat: this.dataFormat, dilationRate: this.dilationRate, activation: Ts(this.activation), useBias: this.useBias, biasInitializer: Qt(this.biasInitializer), biasRegularizer: Wt(this.biasRegularizer), activityRegularizer: Wt(this.activityRegularizer), biasConstraint: de(this.biasConstraint) }, e = super.getConfig(); return Object.assign(t, e), t } } class jo extends sl { constructor(t, e) { super(t, e), this.kernel = null, jo.verifyArgs(e), this.filters = e.filters, ge(this.filters, "filters"), this.kernelInitializer = Ht(e.kernelInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.kernelConstraint = he(e.kernelConstraint), this.kernelRegularizer = _t(e.kernelRegularizer) } build(t) { t = Nt(t); const e = this.dataFormat === "channelsFirst" ? 1 : t.length - 1; if (t[e] == null) throw new $(`The channel dimension of the input should be defined. Found ${t[e]}`); const s = t[e], o = this.kernelSize.concat([s, this.filters]); this.kernel = this.addWeight("kernel", o, null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [{ ndim: this.rank + 2, axes: { [e]: s } }], this.built = !0 } call(t, e) { return M(() => { t = mt(t); let s; const o = this.bias == null ? null : this.bias.read(), r = qg(this.activation.getClassName()); if (r != null && this.rank === 2) s = Ib(t, this.kernel.read(), o, this.strides, this.padding, this.dataFormat, this.dilationRate, r); else { if (this.rank === 1) s = Z$(t, this.kernel.read(), o, this.strides[0], this.padding, this.dataFormat, this.dilationRate[0]); else if (this.rank === 2) s = Ib(t, this.kernel.read(), o, this.strides, this.padding, this.dataFormat, this.dilationRate); else if (this.rank === 3) s = B$(t, this.kernel.read(), o, this.strides, this.padding, this.dataFormat, this.dilationRate); else throw new bt("convolutions greater than 3D are not implemented yet."); this.activation != null && (s = this.activation.apply(s)) } return s }) } computeOutputShape(t) { t = Nt(t); const e = [], s = this.dataFormat === "channelsLast" ? t.slice(1, t.length - 1) : t.slice(2); for (let r = 0; r < s.length; ++r) { const i = Wn(s[r], this.kernelSize[r], this.padding, this.strides[r], typeof this.dilationRate == "number" ? this.dilationRate : this.dilationRate[r]); e.push(i) } let o = [t[0]]; return this.dataFormat === "channelsLast" ? (o = o.concat(e), o.push(this.filters)) : (o.push(this.filters), o = o.concat(e)), o } getConfig() { const t = { filters: this.filters, kernelInitializer: Qt(this.kernelInitializer), kernelRegularizer: Wt(this.kernelRegularizer), kernelConstraint: de(this.kernelConstraint) }, e = super.getConfig(); return Object.assign(t, e), t } static verifyArgs(t) { if (!("filters" in t) || typeof t.filters != "number" || t.filters < 1) throw new $(`Convolution layer expected config.filters to be a 'number' > 0 but got ${JSON.stringify(t.filters)}`) } } class Zi extends jo { constructor(t) { super(2, t), Zi.verifyArgs(t) } getConfig() { const t = super.getConfig(); return delete t.rank, t } static verifyArgs(t) { if (typeof t.kernelSize != "number" && !wh(t.kernelSize, "number", 1, 2)) throw new $(`Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received ${JSON.stringify(t.kernelSize)}.`) } } Zi.className = "Conv2D", _(Zi); class Bi extends jo { constructor(t) { super(3, t), Bi.verifyArgs(t) } getConfig() { const t = super.getConfig(); return delete t.rank, t } static verifyArgs(t) { if (typeof t.kernelSize != "number" && !(Array.isArray(t.kernelSize) && (t.kernelSize.length === 1 || t.kernelSize.length === 3))) throw new $(`Conv3D expects config.kernelSize to be number or [number, number, number], but received ${JSON.stringify(t.kernelSize)}.`) } } Bi.className = "Conv3D", _(Bi); class Cb extends Zi { constructor(t) { if (super(t), this.inputSpec = [new ue({ ndim: 4 })], this.padding !== "same" && this.padding !== "valid") throw new $(`Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`) } build(t) { if (t = Nt(t), t.length !== 4) throw new $("Input should have rank 4; Received input shape: " + JSON.stringify(t)); const e = this.dataFormat === "channelsFirst" ? 1 : t.length - 1; if (t[e] == null) throw new $("The channel dimension of the inputs should be defined. Found `None`."); const s = t[e], o = this.kernelSize.concat([this.filters, s]); this.kernel = this.addWeight("kernel", o, "float32", this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [new ue({ ndim: 4, axes: { [e]: s } })], this.built = !0 } call(t, e) { return M(() => { let s = mt(t); if (s.shape.length !== 4) throw new $(`Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${s.shape.length}`); const o = s.shape, r = o[0]; let i, a; this.dataFormat === "channelsFirst" ? (i = 2, a = 3) : (i = 1, a = 2); const c = o[i], l = o[a], u = this.kernelSize[0], d = this.kernelSize[1], h = this.strides[0], p = this.strides[1], f = _n(c, h, u, this.padding), m = _n(l, p, d, this.padding), g = [r, f, m, this.filters]; this.dataFormat !== "channelsLast" && (s = St(s, [0, 2, 3, 1])); let b = wm(s, this.kernel.read(), g, this.strides, this.padding); return this.dataFormat !== "channelsLast" && (b = St(b, [0, 3, 1, 2])), this.bias != null && (b = Ln(b, this.bias.read(), this.dataFormat)), this.activation != null && (b = this.activation.apply(b)), b }) } computeOutputShape(t) { t = Nt(t); const e = t.slice(); let s, o, r; this.dataFormat === "channelsFirst" ? (s = 1, o = 2, r = 3) : (s = 3, o = 1, r = 2); const i = this.kernelSize[0], a = this.kernelSize[1], c = this.strides[0], l = this.strides[1]; return e[s] = this.filters, e[o] = _n(e[o], c, i, this.padding), e[r] = _n(e[r], l, a, this.padding), e } getConfig() { const t = super.getConfig(); return delete t.dilationRate, t } } Cb.className = "Conv2DTranspose", _(Cb); class wb extends Bi { constructor(t) { if (super(t), this.inputSpec = [new ue({ ndim: 5 })], this.padding !== "same" && this.padding !== "valid") throw new $(`Conv3DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode ${this.padding}`) } build(t) { if (t = Nt(t), t.length !== 5) throw new $("Input should have rank 5; Received input shape: " + JSON.stringify(t)); const e = this.dataFormat === "channelsFirst" ? 1 : t.length - 1; if (t[e] == null) throw new $("The channel dimension of the inputs should be defined. Found `None`."); const s = t[e], o = this.kernelSize.concat([this.filters, s]); this.kernel = this.addWeight("kernel", o, "float32", this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint)), this.inputSpec = [new ue({ ndim: 5, axes: { [e]: s } })], this.built = !0 } call(t, e) { return M(() => { let s = mt(t); if (s.shape.length !== 5) throw new $(`Conv3DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-${s.shape.length}`); const o = s.shape, r = o[0]; let i, a, c; this.dataFormat === "channelsFirst" ? (c = 2, i = 3, a = 4) : (c = 1, i = 2, a = 3); const l = o[c], u = o[i], d = o[a], h = this.kernelSize[0], p = this.kernelSize[1], f = this.kernelSize[2], m = this.strides[0], g = this.strides[1], b = this.strides[2], x = _n(l, m, h, this.padding), I = _n(u, g, p, this.padding), y = _n(d, b, f, this.padding), C = [r, x, I, y, this.filters]; this.dataFormat !== "channelsLast" && (s = St(s, [0, 2, 3, 4, 1])); let w = a2(s, this.kernel.read(), C, this.strides, this.padding); return this.dataFormat !== "channelsLast" && (w = St(w, [0, 4, 1, 2, 3])), this.bias !== null && (w = Ln(w, this.bias.read(), this.dataFormat)), this.activation !== null && (w = this.activation.apply(w)), w }) } computeOutputShape(t) { t = Nt(t); const e = t.slice(); let s, o, r, i; this.dataFormat === "channelsFirst" ? (s = 1, o = 2, r = 3, i = 4) : (s = 4, o = 1, r = 2, i = 3); const a = this.kernelSize[0], c = this.kernelSize[1], l = this.kernelSize[2], u = this.strides[0], d = this.strides[1], h = this.strides[2]; return e[s] = this.filters, e[o] = _n(e[o], u, a, this.padding), e[r] = _n(e[r], d, c, this.padding), e[i] = _n(e[i], h, l, this.padding), e } getConfig() { const t = super.getConfig(); return delete t.dilationRate, t } } wb.className = "Conv3DTranspose", _(wb); class vb extends jo { constructor(t, e) { if (super(t, e), this.DEFAULT_DEPTHWISE_INITIALIZER = "glorotUniform", this.DEFAULT_POINTWISE_INITIALIZER = "glorotUniform", this.depthwiseKernel = null, this.pointwiseKernel = null, e.filters == null) throw new $("The `filters` configuration field is required by SeparableConv, but is unspecified."); if (e.kernelInitializer != null || e.kernelRegularizer != null || e.kernelConstraint != null) throw new $("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead."); if (e.padding != null && e.padding !== "same" && e.padding !== "valid") throw new $(`SeparableConv${this.rank}D supports only padding modes: 'same' and 'valid', but received ${JSON.stringify(e.padding)}`); this.depthMultiplier = e.depthMultiplier == null ? 1 : e.depthMultiplier, this.depthwiseInitializer = Ht(e.depthwiseInitializer || this.DEFAULT_DEPTHWISE_INITIALIZER), this.depthwiseRegularizer = _t(e.depthwiseRegularizer), this.depthwiseConstraint = he(e.depthwiseConstraint), this.pointwiseInitializer = Ht(e.depthwiseInitializer || this.DEFAULT_POINTWISE_INITIALIZER), this.pointwiseRegularizer = _t(e.pointwiseRegularizer), this.pointwiseConstraint = he(e.pointwiseConstraint) } build(t) { if (t = Nt(t), t.length < this.rank + 2) throw new $(`Inputs to SeparableConv${this.rank}D should have rank ${this.rank + 2}, but received input shape: ${JSON.stringify(t)}`); const e = this.dataFormat === "channelsFirst" ? 1 : t.length - 1; if (t[e] == null || t[e] < 0) throw new $(`The channel dimension of the inputs should be defined, but found ${JSON.stringify(t[e])}`); const s = t[e], o = this.kernelSize.concat([s, this.depthMultiplier]), r = []; for (let a = 0; a < this.rank; ++a)r.push(1); r.push(s * this.depthMultiplier, this.filters); const i = !0; this.depthwiseKernel = this.addWeight("depthwise_kernel", o, "float32", this.depthwiseInitializer, this.depthwiseRegularizer, i, this.depthwiseConstraint), this.pointwiseKernel = this.addWeight("pointwise_kernel", r, "float32", this.pointwiseInitializer, this.pointwiseRegularizer, i, this.pointwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.filters], "float32", this.biasInitializer, this.biasRegularizer, i, this.biasConstraint) : this.bias = null, this.inputSpec = [new ue({ ndim: this.rank + 2, axes: { [e]: s } })], this.built = !0 } call(t, e) { return M(() => { t = mt(t); let s; if (this.rank === 1) throw new bt("1D separable convolution is not implemented yet."); return this.rank === 2 && (this.dataFormat === "channelsFirst" && (t = St(t, [0, 2, 3, 1])), s = Om(t, this.depthwiseKernel.read(), this.pointwiseKernel.read(), this.strides, this.padding, this.dilationRate, "NHWC")), this.useBias && (s = Ln(s, this.bias.read(), this.dataFormat)), this.activation != null && (s = this.activation.apply(s)), this.dataFormat === "channelsFirst" && (s = St(s, [0, 3, 1, 2])), s }) } getConfig() { const t = super.getConfig(); return delete t.rank, delete t.kernelInitializer, delete t.kernelRegularizer, delete t.kernelConstraint, t.depthwiseInitializer = Qt(this.depthwiseInitializer), t.pointwiseInitializer = Qt(this.pointwiseInitializer), t.depthwiseRegularizer = Wt(this.depthwiseRegularizer), t.pointwiseRegularizer = Wt(this.pointwiseRegularizer), t.depthwiseConstraint = de(this.depthwiseConstraint), t.pointwiseConstraint = de(this.pointwiseConstraint), t } } vb.className = "SeparableConv"; class Sb extends vb { constructor(t) { super(2, t) } } Sb.className = "SeparableConv2D", _(Sb); class ol extends jo { constructor(t) { super(1, t), ol.verifyArgs(t), this.inputSpec = [{ ndim: 3 }] } getConfig() { const t = super.getConfig(); return delete t.rank, delete t.dataFormat, t } static verifyArgs(t) { if (typeof t.kernelSize != "number" && !wh(t.kernelSize, "number", 1, 1)) throw new $(`Conv1D expects config.kernelSize to be number or number[] with length 1, but received ${JSON.stringify(t.kernelSize)}.`) } } ol.className = "Conv1D", _(ol); class kb extends vt { constructor(t) { super(t), typeof t.cropping == "number" ? this.cropping = [[t.cropping, t.cropping], [t.cropping, t.cropping]] : typeof t.cropping[0] == "number" ? this.cropping = [[t.cropping[0], t.cropping[0]], [t.cropping[1], t.cropping[1]]] : this.cropping = t.cropping, this.dataFormat = t.dataFormat === void 0 ? "channelsLast" : t.dataFormat, this.inputSpec = [{ ndim: 4 }] } computeOutputShape(t) { return this.dataFormat === "channelsFirst" ? [t[0], t[1], t[2] - this.cropping[0][0] - this.cropping[0][1], t[3] - this.cropping[1][0] - this.cropping[1][1]] : [t[0], t[1] - this.cropping[0][0] - this.cropping[0][1], t[2] - this.cropping[1][0] - this.cropping[1][1], t[3]] } call(t, e) { return M(() => { if (t = mt(t), this.dataFormat === "channelsLast") { const s = Pc(t, this.cropping[0][0], t.shape[1] - this.cropping[0][0] - this.cropping[0][1], 2); return Pc(s, this.cropping[1][0], t.shape[2] - this.cropping[1][1] - this.cropping[1][0], 3) } else { const s = Pc(t, this.cropping[0][0], t.shape[2] - this.cropping[0][0] - this.cropping[0][1], 3); return Pc(s, this.cropping[1][0], t.shape[3] - this.cropping[1][1] - this.cropping[1][0], 4) } }) } getConfig() { const t = { cropping: this.cropping, dataFormat: this.dataFormat }, e = super.getConfig(); return Object.assign(t, e), t } } kb.className = "Cropping2D", _(kb); class Tb extends vt { constructor(t) { super(t), this.DEFAULT_SIZE = [2, 2], this.inputSpec = [{ ndim: 4 }], this.size = t.size == null ? this.DEFAULT_SIZE : t.size, this.dataFormat = t.dataFormat == null ? "channelsLast" : t.dataFormat, ee(this.dataFormat), this.interpolation = t.interpolation == null ? "nearest" : t.interpolation, kR(this.interpolation) } computeOutputShape(t) { if (this.dataFormat === "channelsFirst") { const e = t[2] == null ? null : this.size[0] * t[2], s = t[3] == null ? null : this.size[1] * t[3]; return [t[0], t[1], e, s] } else { const e = t[1] == null ? null : this.size[0] * t[1], s = t[2] == null ? null : this.size[1] * t[2]; return [t[0], e, s, t[3]] } } call(t, e) { return M(() => { let s = mt(t); const o = s.shape; if (this.dataFormat === "channelsFirst") { s = St(s, [0, 2, 3, 1]); const r = this.size[0] * o[2], i = this.size[1] * o[3], a = this.interpolation === "nearest" ? io.resizeNearestNeighbor(s, [r, i]) : io.resizeBilinear(s, [r, i]); return St(a, [0, 3, 1, 2]) } else { const r = this.size[0] * o[1], i = this.size[1] * o[2]; return this.interpolation === "nearest" ? io.resizeNearestNeighbor(s, [r, i]) : io.resizeBilinear(s, [r, i]) } }) } getConfig() { const t = { size: this.size, dataFormat: this.dataFormat, interpolation: this.interpolation }, e = super.getConfig(); return Object.assign(t, e), t } } Tb.className = "UpSampling2D", _(Tb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function H$(n, t, e = [1, 1], s = "valid", o, r) { return M(() => { o == null && (o = Gn()), ee(o); let i = Jh(n, o); if (n.rank !== 4) throw new $(`Input for depthwiseConv2d is required to be 4-D, but is instead ${n.rank}-D`); if (t.rank !== 4) throw new $(`depthwiseKernel is required to be 4-D, but is instead ${t.rank}-D`); return i = dd(i, t, e, s === "same" ? "same" : "valid", "NHWC", r), o === "channelsFirst" && (i = St(i, [0, 3, 1, 2])), i }) } class Nb extends sl { constructor(t) { super(2, t), this.depthwiseKernel = null, this.depthMultiplier = t.depthMultiplier == null ? 1 : t.depthMultiplier, this.depthwiseInitializer = Ht(t.depthwiseInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.depthwiseConstraint = he(t.depthwiseConstraint), this.depthwiseRegularizer = _t(t.depthwiseRegularizer) } build(t) { if (t = Nt(t), t.length < 4) throw new $(`Inputs to DepthwiseConv2D should have rank 4. Received input shape: ${JSON.stringify(t)}.`); const e = this.dataFormat === "channelsFirst" ? 1 : 3; if (t[e] == null || t[e] < 0) throw new $(`The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not (${t[e]}).`); const s = t[e], o = [this.kernelSize[0], this.kernelSize[1], s, this.depthMultiplier]; this.depthwiseKernel = this.addWeight("depthwise_kernel", o, null, this.depthwiseInitializer, this.depthwiseRegularizer, !0, this.depthwiseConstraint), this.useBias ? this.bias = this.addWeight("bias", [s * this.depthMultiplier], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0 } call(t, e) { return M(() => { t = mt(t); let s = H$(t, this.depthwiseKernel.read(), this.strides, this.padding, this.dataFormat, null); return this.useBias && (s = Ln(s, this.bias.read(), this.dataFormat)), this.activation != null && (s = this.activation.apply(s)), s }) } computeOutputShape(t) { t = Nt(t); const e = this.dataFormat === "channelsFirst" ? t[2] : t[1], s = this.dataFormat === "channelsFirst" ? t[3] : t[2], o = this.dataFormat === "channelsFirst" ? t[1] * this.depthMultiplier : t[3] * this.depthMultiplier, r = Wn(e, this.kernelSize[0], this.padding, this.strides[0]), i = Wn(s, this.kernelSize[1], this.padding, this.strides[1]); return this.dataFormat === "channelsFirst" ? [t[0], o, r, i] : [t[0], r, i, o] } getConfig() { const t = super.getConfig(); return t.depthMultiplier = this.depthMultiplier, t.depthwiseInitializer = Qt(this.depthwiseInitializer), t.depthwiseRegularizer = Wt(this.depthwiseRegularizer), t.depthwiseConstraint = de(this.depthwiseRegularizer), t } } Nb.className = "DepthwiseConv2D", _(Nb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function Rb(n, t, e, s) { if (Array.isArray(n)) { if (t != null || e != null) throw new $("When inputs is an array, neither initialState or constants should be provided"); s != null && (e = n.slice(n.length - s, n.length), n = n.slice(0, n.length - s)), n.length > 1 && (t = n.slice(1, n.length)), n = n[0] } function o(r) { return r == null || Array.isArray(r) ? r : [r] } return t = o(t), e = o(e), { inputs: n, initialState: t, constants: e } } function $b(n, t, e, s = !1, o, r, i = !1, a = !1) { return M(() => { const c = t.shape.length; if (c < 3) throw new $(`Input should be at least 3D, but is ${c}D.`); const l = [1, 0].concat($n(2, c)); if (t = St(t, l), r != null) throw new bt("The rnn() functoin of the deeplearn.js backend does not support constants yet."); i && console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."), o != null && (o = ot(ot(o, "bool"), "float32"), o.rank === c - 1 && (o = He(o, -1)), o = St(o, l)), s && (t = oo(t, 0), o != null && (o = oo(o, 0))); const u = []; let d, h = e; const p = t.shape[0], f = ro(t); let m; o != null && (m = ro(o)); for (let b = 0; b < p; ++b) { const x = f[b], I = M(() => n(x, h)); if (o == null) d = I[0], h = I[1]; else { const y = M(() => { const C = m[b], w = ft(pn(C), C), k = Q(E(I[0], C), E(h[0], w)), S = h.map((T, R) => Q(E(I[1][R], C), E(T, w))); return { output: k, newStates: S } }); d = y.output, h = y.newStates } a && u.push(d) } let g; return a && (g = os(u, 1)), [d, g, h] }) } class Rs extends vt { constructor(t) { super(t); let e; if (t.cell == null) throw new $("cell property is missing for the constructor of RNN."); if (Array.isArray(t.cell) ? e = new tp({ cells: t.cell }) : e = t.cell, e.stateSize == null) throw new $("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state)."); this.cell = e, this.returnSequences = t.returnSequences == null ? !1 : t.returnSequences, this.returnState = t.returnState == null ? !1 : t.returnState, this.goBackwards = t.goBackwards == null ? !1 : t.goBackwards, this._stateful = t.stateful == null ? !1 : t.stateful, this.unroll = t.unroll == null ? !1 : t.unroll, this.supportsMasking = !0, this.inputSpec = [new ue({ ndim: 3 })], this.stateSpec = null, this.states_ = null, this.numConstants = null, this.keptStates = [] } getStates() { if (this.states_ == null) { const t = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1; return $n(0, t).map(e => null) } else return this.states_ } setStates(t) { this.states_ = t } computeOutputShape(t) { Mh(t) && (t = t[0]), t = t; let e = this.cell.stateSize; Array.isArray(e) || (e = [e]); const s = e[0]; let o; if (this.returnSequences ? o = [t[0], t[1], s] : o = [t[0], s], this.returnState) { const r = []; for (const i of e) r.push([t[0], i]); return [o].concat(r) } else return o } computeMask(t, e) { return M(() => { Array.isArray(e) && (e = e[0]); const s = this.returnSequences ? e : null; if (this.returnState) { const o = this.states.map(r => null); return [s].concat(o) } else return s }) } get states() { if (this.states_ == null) { const t = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1, e = []; for (let s = 0; s < t; ++s)e.push(null); return e } else return this.states_ } set states(t) { this.states_ = t } build(t) { if (this.numConstants != null) throw new bt("Constants support is not implemented in RNN yet."); Mh(t) && (t = t[0]), t = t; const e = this.stateful ? t[0] : null, s = t.slice(2); this.inputSpec[0] = new ue({ shape: [e, null, ...s] }); const o = [t[0]].concat(t.slice(2)); this.cell.build(o); let r; if (Array.isArray(this.cell.stateSize) ? r = this.cell.stateSize : r = [this.cell.stateSize], this.stateSpec != null) { if (!Rt(this.stateSpec.map(i => i.shape[i.shape.length - 1]), r)) throw new $(`An initialState was passed that is not compatible with cell.stateSize. Received stateSpec=${this.stateSpec}; However cell.stateSize is ${this.cell.stateSize}`) } else this.stateSpec = r.map(i => new ue({ shape: [null, i] })); this.stateful && this.resetStates() } resetStates(t, e = !1) { M(() => { if (!this.stateful) throw new Pn("Cannot call resetStates() on an RNN Layer that is not stateful."); const s = this.inputSpec[0].shape[0]; if (s == null) throw new $("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer."); if (this.states_ == null) Array.isArray(this.cell.stateSize) ? this.states_ = this.cell.stateSize.map(o => me([s, o])) : this.states_ = [me([s, this.cell.stateSize])]; else if (t == null) wt(this.states_), this.keptStates != null && (wt(this.keptStates), this.keptStates = []), Array.isArray(this.cell.stateSize) ? this.states_ = this.cell.stateSize.map(o => me([s, o])) : this.states_[0] = me([s, this.cell.stateSize]); else { if (Array.isArray(t) || (t = [t]), t.length !== this.states_.length) throw new $(`Layer ${this.name} expects ${this.states_.length} state(s), but it received ${t.length} state value(s). Input received: ${t}`); e === !0 ? this.keptStates.push(this.states_.slice()) : wt(this.states_); for (let o = 0; o < this.states_.length; ++o) { const r = t[o], i = Array.isArray(this.cell.stateSize) ? this.cell.stateSize[o] : this.cell.stateSize, a = [s, i]; if (!Rt(r.shape, a)) throw new $(`State ${o} is incompatible with layer ${this.name}: expected shape=${a}, received shape=${r.shape}`); this.states_[o] = r } } this.states_ = this.states_.map(o => tn(o.clone())) }) } apply(t, e) { let s = e == null ? null : e.initialState, o = e == null ? null : e.constants; e == null && (e = {}); const r = Rb(t, s, o, this.numConstants); t = r.inputs, s = r.initialState, o = r.constants; let i = [], a = []; if (s != null) { e.initialState = s, i = i.concat(s), this.stateSpec = []; for (const l of s) this.stateSpec.push(new ue({ shape: l.shape })); a = a.concat(this.stateSpec) } if (o != null && (e.constants = o, i = i.concat(o), this.numConstants = o.length), i[0] instanceof Hn) { const l = [t].concat(i), u = this.inputSpec.concat(a), d = this.inputSpec; this.inputSpec = u; const h = super.apply(l, e); return this.inputSpec = d, h } else return super.apply(t, e) } call(t, e) { return M(() => { const s = e == null ? null : e.mask, o = e == null ? null : e.training; let r = e == null ? null : e.initialState; t = mt(t), r == null && (this.stateful ? r = this.states_ : r = this.getInitialState(t)); const i = Array.isArray(this.cell.stateSize) ? this.cell.stateSize.length : 1; if (r.length !== i) throw new $(`RNN Layer has ${i} state(s) but was passed ${r.length} initial state(s).`); this.unroll && console.warn("Ignoring unroll = true for RNN layer, due to imperative backend."); const a = { training: o }, l = $b((f, m) => { const g = this.cell.call([f].concat(m), a); return [g[0], g.slice(1)] }, t, r, this.goBackwards, s, null, this.unroll, this.returnSequences), u = l[0], d = l[1], h = l[2]; this.stateful && this.resetStates(h, o); const p = this.returnSequences ? d : u; return this.returnState ? [p].concat(h) : p }) } getInitialState(t) { return M(() => { let e = me(t.shape); return e = ut(e, [1, 2]), e = Wi(e), Array.isArray(this.cell.stateSize) ? this.cell.stateSize.map(s => s > 1 ? Th(e, [1, s]) : e) : this.cell.stateSize > 1 ? [Th(e, [1, this.cell.stateSize])] : [e] }) } get trainableWeights() { return this.trainable ? this.cell.trainableWeights : [] } get nonTrainableWeights() { return this.trainable ? this.cell.nonTrainableWeights : this.cell.weights } setFastWeightInitDuringBuild(t) { super.setFastWeightInitDuringBuild(t), this.cell != null && this.cell.setFastWeightInitDuringBuild(t) } getConfig() { const t = super.getConfig(), e = { returnSequences: this.returnSequences, returnState: this.returnState, goBackwards: this.goBackwards, stateful: this.stateful, unroll: this.unroll }; this.numConstants != null && (e.numConstants = this.numConstants); const s = this.cell.getConfig(); return this.getClassName() === Rs.className && (e.cell = { className: this.cell.getClassName(), config: s }), Object.assign(Object.assign(Object.assign({}, s), t), e) } static fromConfig(t, e, s = {}) { const o = e.cell, r = as(o, s); return new t(Object.assign(e, { cell: r })) } } Rs.className = "RNN", _(Rs); class rl extends vt { } class jh extends rl { constructor(t) { super(t), this.DEFAULT_ACTIVATION = "tanh", this.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", this.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", this.DEFAULT_BIAS_INITIALIZER = "zeros", this.units = t.units, ge(this.units, "units"), this.activation = Ns(t.activation == null ? this.DEFAULT_ACTIVATION : t.activation), this.useBias = t.useBias == null ? !0 : t.useBias, this.kernelInitializer = Ht(t.kernelInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.recurrentInitializer = Ht(t.recurrentInitializer || this.DEFAULT_RECURRENT_INITIALIZER), this.biasInitializer = Ht(t.biasInitializer || this.DEFAULT_BIAS_INITIALIZER), this.kernelRegularizer = _t(t.kernelRegularizer), this.recurrentRegularizer = _t(t.recurrentRegularizer), this.biasRegularizer = _t(t.biasRegularizer), this.kernelConstraint = he(t.kernelConstraint), this.recurrentConstraint = he(t.recurrentConstraint), this.biasConstraint = he(t.biasConstraint), this.dropout = Yo([1, Ss([0, t.dropout == null ? 0 : t.dropout])]), this.recurrentDropout = Yo([1, Ss([0, t.recurrentDropout == null ? 0 : t.recurrentDropout])]), this.dropoutFunc = t.dropoutFunc, this.stateSize = this.units, this.dropoutMask = null, this.recurrentDropoutMask = null } build(t) { t = Nt(t), this.kernel = this.addWeight("kernel", [t[t.length - 1], this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0 } call(t, e) { return M(() => { if (t = t, t.length !== 2) throw new $(`SimpleRNNCell expects 2 input Tensors, got ${t.length}.`); let s = t[1]; t = t[0]; const o = e.training == null ? !1 : e.training; 0 < this.dropout && this.dropout < 1 && this.dropoutMask == null && (this.dropoutMask = $s({ ones: () => pn(t), rate: this.dropout, training: o, dropoutFunc: this.dropoutFunc })), 0 < this.recurrentDropout && this.recurrentDropout < 1 && this.recurrentDropoutMask == null && (this.recurrentDropoutMask = $s({ ones: () => pn(s), rate: this.recurrentDropout, training: o, dropoutFunc: this.dropoutFunc })); let r; const i = this.dropoutMask, a = this.recurrentDropoutMask; i != null ? r = Bn(E(t, i), this.kernel.read()) : r = Bn(t, this.kernel.read()), this.bias != null && (r = Ln(r, this.bias.read())), a != null && (s = E(s, a)); let c = Q(r, Bn(s, this.recurrentKernel.read())); return this.activation != null && (c = this.activation.apply(c)), [c, c] }) } getConfig() { const t = super.getConfig(), e = { units: this.units, activation: Ts(this.activation), useBias: this.useBias, kernelInitializer: Qt(this.kernelInitializer), recurrentInitializer: Qt(this.recurrentInitializer), biasInitializer: Qt(this.biasInitializer), kernelRegularizer: Wt(this.kernelRegularizer), recurrentRegularizer: Wt(this.recurrentRegularizer), biasRegularizer: Wt(this.biasRegularizer), activityRegularizer: Wt(this.activityRegularizer), kernelConstraint: de(this.kernelConstraint), recurrentConstraint: de(this.recurrentConstraint), biasConstraint: de(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout }; return Object.assign(Object.assign({}, t), e) } } jh.className = "SimpleRNNCell", _(jh); class Gb extends Rs { constructor(t) { t.cell = new jh(t), super(t) } call(t, e) { return M(() => { this.cell.dropoutMask != null && (wt(this.cell.dropoutMask), this.cell.dropoutMask = null), this.cell.recurrentDropoutMask != null && (wt(this.cell.recurrentDropoutMask), this.cell.recurrentDropoutMask = null); const s = e == null ? null : e.mask, o = e == null ? null : e.training, r = e == null ? null : e.initialState; return super.call(t, { mask: s, training: o, initialState: r }) }) } static fromConfig(t, e) { return new t(e) } } Gb.className = "SimpleRNN", _(Gb); class qh extends rl { constructor(t) { if (super(t), this.DEFAULT_ACTIVATION = "tanh", this.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", this.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", this.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", this.DEFAULT_BIAS_INITIALIZER = "zeros", t.resetAfter) throw new $("GRUCell does not support reset_after parameter set to true."); this.units = t.units, ge(this.units, "units"), this.activation = Ns(t.activation === void 0 ? this.DEFAULT_ACTIVATION : t.activation), this.recurrentActivation = Ns(t.recurrentActivation === void 0 ? this.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), this.useBias = t.useBias == null ? !0 : t.useBias, this.kernelInitializer = Ht(t.kernelInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.recurrentInitializer = Ht(t.recurrentInitializer || this.DEFAULT_RECURRENT_INITIALIZER), this.biasInitializer = Ht(t.biasInitializer || this.DEFAULT_BIAS_INITIALIZER), this.kernelRegularizer = _t(t.kernelRegularizer), this.recurrentRegularizer = _t(t.recurrentRegularizer), this.biasRegularizer = _t(t.biasRegularizer), this.kernelConstraint = he(t.kernelConstraint), this.recurrentConstraint = he(t.recurrentConstraint), this.biasConstraint = he(t.biasConstraint), this.dropout = Yo([1, Ss([0, t.dropout == null ? 0 : t.dropout])]), this.recurrentDropout = Yo([1, Ss([0, t.recurrentDropout == null ? 0 : t.recurrentDropout])]), this.dropoutFunc = t.dropoutFunc, this.implementation = t.implementation, this.stateSize = this.units, this.dropoutMask = null, this.recurrentDropoutMask = null } build(t) { t = Nt(t); const e = t[t.length - 1]; this.kernel = this.addWeight("kernel", [e, this.units * 3], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units * 3], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias ? this.bias = this.addWeight("bias", [this.units * 3], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint) : this.bias = null, this.built = !0 } call(t, e) { return M(() => { if (t = t, t.length !== 2) throw new $(`GRUCell expects 2 input Tensors (inputs, h, c), got ${t.length}.`); const s = e.training == null ? !1 : e.training; let o = t[1]; t = t[0], 0 < this.dropout && this.dropout < 1 && this.dropoutMask == null && (this.dropoutMask = $s({ ones: () => pn(t), rate: this.dropout, training: s, count: 3, dropoutFunc: this.dropoutFunc })), 0 < this.recurrentDropout && this.recurrentDropout < 1 && this.recurrentDropoutMask == null && (this.recurrentDropoutMask = $s({ ones: () => pn(o), rate: this.recurrentDropout, training: s, count: 3, dropoutFunc: this.dropoutFunc })); const r = this.dropoutMask, i = this.recurrentDropoutMask; let a, c, l; 0 < this.dropout && this.dropout < 1 && (t = E(t, r[0])); let u = Bn(t, this.kernel.read()); this.useBias && (u = Ln(u, this.bias.read())), 0 < this.recurrentDropout && this.recurrentDropout < 1 && (o = E(o, i[0])); const d = this.recurrentKernel.read(), [h, p] = sn(d, [2 * this.units, this.units], d.rank - 1), f = Bn(o, h), [m, g, b] = sn(u, 3, u.rank - 1), [x, I] = sn(f, 2, f.rank - 1); a = this.recurrentActivation.apply(Q(m, x)), c = this.recurrentActivation.apply(Q(g, I)); const y = Bn(E(c, o), p); l = this.activation.apply(Q(b, y)); const C = Q(E(a, o), E(Q(1, re(a)), l)); return [C, C] }) } getConfig() { const t = super.getConfig(), e = { units: this.units, activation: Ts(this.activation), recurrentActivation: Ts(this.recurrentActivation), useBias: this.useBias, kernelInitializer: Qt(this.kernelInitializer), recurrentInitializer: Qt(this.recurrentInitializer), biasInitializer: Qt(this.biasInitializer), kernelRegularizer: Wt(this.kernelRegularizer), recurrentRegularizer: Wt(this.recurrentRegularizer), biasRegularizer: Wt(this.biasRegularizer), activityRegularizer: Wt(this.activityRegularizer), kernelConstraint: de(this.kernelConstraint), recurrentConstraint: de(this.recurrentConstraint), biasConstraint: de(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout, implementation: this.implementation, resetAfter: !1 }; return Object.assign(Object.assign({}, t), e) } } qh.className = "GRUCell", _(qh); class Lb extends Rs { constructor(t) { t.implementation === 0 && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), t.cell = new qh(t), super(t) } call(t, e) { return M(() => { this.cell.dropoutMask != null && (wt(this.cell.dropoutMask), this.cell.dropoutMask = null), this.cell.recurrentDropoutMask != null && (wt(this.cell.recurrentDropoutMask), this.cell.recurrentDropoutMask = null); const s = e == null ? null : e.mask, o = e == null ? null : e.training, r = e == null ? null : e.initialState; return super.call(t, { mask: s, training: o, initialState: r }) }) } static fromConfig(t, e) { return e.implmentation === 0 && (e.implementation = 1), new t(e) } } Lb.className = "GRU", _(Lb); class il extends rl { constructor(t) { super(t), this.DEFAULT_ACTIVATION = "tanh", this.DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid", this.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", this.DEFAULT_RECURRENT_INITIALIZER = "orthogonal", this.DEFAULT_BIAS_INITIALIZER = "zeros", this.units = t.units, ge(this.units, "units"), this.activation = Ns(t.activation === void 0 ? this.DEFAULT_ACTIVATION : t.activation), this.recurrentActivation = Ns(t.recurrentActivation === void 0 ? this.DEFAULT_RECURRENT_ACTIVATION : t.recurrentActivation), this.useBias = t.useBias == null ? !0 : t.useBias, this.kernelInitializer = Ht(t.kernelInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.recurrentInitializer = Ht(t.recurrentInitializer || this.DEFAULT_RECURRENT_INITIALIZER), this.biasInitializer = Ht(t.biasInitializer || this.DEFAULT_BIAS_INITIALIZER), this.unitForgetBias = t.unitForgetBias, this.kernelRegularizer = _t(t.kernelRegularizer), this.recurrentRegularizer = _t(t.recurrentRegularizer), this.biasRegularizer = _t(t.biasRegularizer), this.kernelConstraint = he(t.kernelConstraint), this.recurrentConstraint = he(t.recurrentConstraint), this.biasConstraint = he(t.biasConstraint), this.dropout = Yo([1, Ss([0, t.dropout == null ? 0 : t.dropout])]), this.recurrentDropout = Yo([1, Ss([0, t.recurrentDropout == null ? 0 : t.recurrentDropout])]), this.dropoutFunc = t.dropoutFunc, this.implementation = t.implementation, this.stateSize = [this.units, this.units], this.dropoutMask = null, this.recurrentDropoutMask = null } build(t) { var e; t = Nt(t); const s = t[t.length - 1]; this.kernel = this.addWeight("kernel", [s, this.units * 4], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.recurrentKernel = this.addWeight("recurrent_kernel", [this.units, this.units * 4], null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint); let o; if (this.useBias) { if (this.unitForgetBias) { const r = this.biasInitializer, i = this.units; o = new (e = class extends bn { apply(c, l) { const u = r.apply([i]), d = new Rh().apply([i]), h = r.apply([i * 2]); return i0(i0(u, d), h) } }, e.className = "CustomInit", e) } else o = this.biasInitializer; this.bias = this.addWeight("bias", [this.units * 4], null, o, this.biasRegularizer, !0, this.biasConstraint) } else this.bias = null; this.built = !0 } call(t, e) { return M(() => { const s = e.training == null ? !1 : e.training; if (t = t, t.length !== 3) throw new $(`LSTMCell expects 3 input Tensors (inputs, h, c), got ${t.length}.`); let o = t[1]; const r = t[2]; t = t[0], 0 < this.dropout && this.dropout < 1 && this.dropoutMask == null && (this.dropoutMask = $s({ ones: () => pn(t), rate: this.dropout, training: s, count: 4, dropoutFunc: this.dropoutFunc })), 0 < this.recurrentDropout && this.recurrentDropout < 1 && this.recurrentDropoutMask == null && (this.recurrentDropoutMask = $s({ ones: () => pn(o), rate: this.recurrentDropout, training: s, count: 4, dropoutFunc: this.dropoutFunc })); const i = this.dropoutMask, a = this.recurrentDropoutMask; let c, l, u, d; 0 < this.dropout && this.dropout < 1 && (t = E(t, i[0])); let h = Bn(t, this.kernel.read()); 0 < this.recurrentDropout && this.recurrentDropout < 1 && (o = E(o, a[0])), h = Q(h, Bn(o, this.recurrentKernel.read())), this.useBias && (h = Ln(h, this.bias.read())); const [p, f, m, g] = sn(h, 4, h.rank - 1); c = this.recurrentActivation.apply(p), l = this.recurrentActivation.apply(f), u = Q(E(l, r), E(c, this.activation.apply(m))), d = this.recurrentActivation.apply(g); const b = E(d, this.activation.apply(u)); return [b, b, u] }) } getConfig() { const t = super.getConfig(), e = { units: this.units, activation: Ts(this.activation), recurrentActivation: Ts(this.recurrentActivation), useBias: this.useBias, kernelInitializer: Qt(this.kernelInitializer), recurrentInitializer: Qt(this.recurrentInitializer), biasInitializer: Qt(this.biasInitializer), unitForgetBias: this.unitForgetBias, kernelRegularizer: Wt(this.kernelRegularizer), recurrentRegularizer: Wt(this.recurrentRegularizer), biasRegularizer: Wt(this.biasRegularizer), activityRegularizer: Wt(this.activityRegularizer), kernelConstraint: de(this.kernelConstraint), recurrentConstraint: de(this.recurrentConstraint), biasConstraint: de(this.biasConstraint), dropout: this.dropout, recurrentDropout: this.recurrentDropout, implementation: this.implementation }; return Object.assign(Object.assign({}, t), e) } } il.className = "LSTMCell", _(il); class Eb extends Rs { constructor(t) { t.implementation === 0 && console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."), t.cell = new il(t), super(t) } call(t, e) { return M(() => { this.cell.dropoutMask != null && (wt(this.cell.dropoutMask), this.cell.dropoutMask = null), this.cell.recurrentDropoutMask != null && (wt(this.cell.recurrentDropoutMask), this.cell.recurrentDropoutMask = null); const s = e == null ? null : e.mask, o = e == null ? null : e.training, r = e == null ? null : e.initialState; return super.call(t, { mask: s, training: o, initialState: r }) }) } static fromConfig(t, e) { return e.implmentation === 0 && (e.implementation = 1), new t(e) } } Eb.className = "LSTM", _(Eb); class tp extends rl { constructor(t) { super(t), this.cells = t.cells } get stateSize() { const t = []; for (const e of this.cells.slice().reverse()) Array.isArray(e.stateSize) ? t.push(...e.stateSize) : t.push(e.stateSize); return t } call(t, e) { return M(() => { t = t; let s = t.slice(1); const o = []; for (const a of this.cells.slice().reverse()) Array.isArray(a.stateSize) ? o.push(s.splice(0, a.stateSize.length)) : o.push(s.splice(0, 1)); o.reverse(); const r = []; let i; for (let a = 0; a < this.cells.length; ++a) { const c = this.cells[a]; s = o[a], a === 0 ? i = [t[0]].concat(s) : i = [i[0]].concat(s), i = c.call(i, e), r.push(i.slice(1)) } s = []; for (const a of r.slice().reverse()) s.push(...a); return [i[0]].concat(s) }) } build(t) { Mh(t) && (t = t[0]), t = t; let e; this.cells.forEach((s, o) => { po(`RNNCell_${o}`, () => { s.build(t), Array.isArray(s.stateSize) ? e = s.stateSize[0] : e = s.stateSize, t = [t[0], e] }) }), this.built = !0 } getConfig() { const t = super.getConfig(), e = r => ({ className: r.getClassName(), config: r.getConfig() }), o = { cells: this.cells.map(e) }; return Object.assign(Object.assign({}, t), o) } static fromConfig(t, e, s = {}) { const o = []; for (const r of e.cells) o.push(as(r, s)); return new t({ cells: o }) } get trainableWeights() { if (!this.trainable) return []; const t = []; for (const e of this.cells) t.push(...e.trainableWeights); return t } get nonTrainableWeights() { const t = []; for (const e of this.cells) t.push(...e.nonTrainableWeights); if (!this.trainable) { const e = []; for (const s of this.cells) e.push(...s.trainableWeights); return e.concat(t) } return t } getWeights() { const t = []; for (const e of this.cells) t.push(...e.weights); return Fh(t) } setWeights(t) { const e = []; for (const s of this.cells) { const o = s.weights.length, r = t.splice(o); for (let i = 0; i < s.weights.length; ++i)e.push([s.weights[i], r[i]]) } Vh(e) } } tp.className = "StackedRNNCells", _(tp); function $s(n) { const { ones: t, rate: e, training: s = !1, count: o = 1, dropoutFunc: r } = n, i = () => r != null ? r(t(), e) : c0(t(), e), a = () => Fi(i, t, s); return !o || o <= 1 ? tn(a().clone()) : Array(o).fill(void 0).map(a).map(l => tn(l.clone())) }/**
 * @license
 * Copyright 2020 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */var _$ = globalThis && globalThis.__rest || function (n, t) { var e = {}; for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && t.indexOf(s) < 0 && (e[s] = n[s]); if (n != null && typeof Object.getOwnPropertySymbols == "function") for (var o = 0, s = Object.getOwnPropertySymbols(n); o < s.length; o++)t.indexOf(s[o]) < 0 && Object.prototype.propertyIsEnumerable.call(n, s[o]) && (e[s[o]] = n[s[o]]); return e }; class Db extends Rs { constructor(t) { if (t.unroll) throw new bt("Unrolling is not possible with convolutional RNNs."); if (Array.isArray(t.cell)) throw new bt("It is not possible at the moment to stack convolutional cells."); super(t), this.inputSpec = [new ue({ ndim: 5 })] } call(t, e) { return M(() => { if (this.cell.dropoutMask != null && (wt(this.cell.dropoutMask), this.cell.dropoutMask = null), this.cell.recurrentDropoutMask != null && (wt(this.cell.recurrentDropoutMask), this.cell.recurrentDropoutMask = null), e && e.constants) throw new $("ConvRNN2D cell does not support constants"); const s = e == null ? null : e.mask, o = e == null ? null : e.training, r = e == null ? null : e.initialState; return super.call(t, { mask: s, training: o, initialState: r }) }) } computeOutputShape(t) { let e = this.computeSingleOutputShape(t); return this.returnSequences || (e = [e[0], ...e.slice(2)]), this.returnState && (e = [e, ...Array(2).fill([t[0], ...e.slice(-3)])]), e } getInitialState(t) { return M(() => { const { stateSize: e } = this.cell, s = t.shape, o = this.computeSingleOutputShape(s), r = [o[0], ...o.slice(2)], i = me(r); return Array.isArray(e) ? Array(e.length).fill(i) : [i] }) } resetStates(t, e = !1) { M(() => { if (!this.stateful) throw new Pn("Cannot call resetStates() on an RNN Layer that is not stateful."); const s = this.inputSpec[0].shape, o = this.computeSingleOutputShape(s), r = [o[0], ...o.slice(2)]; if (s[0] == null) throw new $("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer."); if (this.getStates() == null) Array.isArray(this.cell.stateSize) ? this.states_ = this.cell.stateSize.map(() => me(r)) : this.states_ = [me(r)]; else if (t == null) wt(this.states_), this.keptStates != null && (wt(this.keptStates), this.keptStates = []), Array.isArray(this.cell.stateSize) ? this.states_ = this.cell.stateSize.map(() => me(r)) : this.states_[0] = me(r); else { if (Array.isArray(t) || (t = [t]), t.length !== this.states_.length) throw new $(`Layer ${this.name} expects ${this.states_.length} state(s), but it received ${t.length} state value(s). Input received: ${t}`); e ? this.keptStates.push(this.states_.slice()) : wt(this.states_); for (let a = 0; a < this.states_.length; ++a) { const c = t[a], l = r; if (!Rt(c.shape, l)) throw new $(`State ${a} is incompatible with layer ${this.name}: expected shape=${l}, received shape=${c.shape}`); this.states_[a] = c } } this.states_ = this.states_.map(a => tn(a.clone())) }) } computeSingleOutputShape(t) { const { dataFormat: e, filters: s, kernelSize: o, padding: r, strides: i, dilationRate: a } = this.cell, c = e === "channelsFirst", l = t[c ? 3 : 2], u = t[c ? 4 : 3], d = Wn(l, o[0], r, i[0], a[0]), h = Wn(u, o[1], r, i[1], a[1]); return [...t.slice(0, 2), ...c ? [s, d, h] : [d, h, s]] } } Db.className = "ConvRNN2D"; class ep extends il { constructor(t) { const { filters: e, kernelSize: s, strides: o, padding: r, dataFormat: i, dilationRate: a } = t; super(Object.assign(Object.assign({}, t), { units: e })), this.filters = e, ge(this.filters, "filters"), this.kernelSize = Jo(s, 2, "kernelSize"), this.kernelSize.forEach(c => ge(c, "kernelSize")), this.strides = Jo(o || 1, 2, "strides"), this.strides.forEach(c => ge(c, "strides")), this.padding = r || "valid", rn(this.padding), this.dataFormat = i || "channelsLast", ee(this.dataFormat), this.dilationRate = Jo(a || 1, 2, "dilationRate"), this.dilationRate.forEach(c => ge(c, "dilationRate")) } build(t) { var e; t = Nt(t); const s = this.dataFormat === "channelsFirst" ? 1 : t.length - 1; if (t[s] == null) throw new $(`The channel dimension of the input should be defined. Found ${t[s]}`); const o = t[s], r = 4, i = this.kernelSize.concat([o, this.filters * r]); this.kernel = this.addWeight("kernel", i, null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint); const a = this.kernelSize.concat([this.filters, this.filters * r]); if (this.recurrentKernel = this.addWeight("recurrent_kernel", a, null, this.recurrentInitializer, this.recurrentRegularizer, !0, this.recurrentConstraint), this.useBias) { let c; if (this.unitForgetBias) { const l = this.biasInitializer, u = this.filters; c = new (e = class extends bn { apply(h, p) { const f = l.apply([u]), m = eo([u]), g = l.apply([u * 2]); return kh([f, m, g]) } }, e.className = "CustomInit", e) } else c = this.biasInitializer; this.bias = this.addWeight("bias", [this.filters * r], null, c, this.biasRegularizer, !0, this.biasConstraint) } this.built = !0 } call(t, e) { return M(() => { if (t.length !== 3) throw new $(`ConvLSTM2DCell expects 3 input Tensors (inputs, h, c), got ${t.length}.`); const s = e.training || !1, o = t[0], r = t[1], i = t[2], a = 4; 0 < this.dropout && this.dropout < 1 && this.dropoutMask == null && (this.dropoutMask = $s({ ones: () => pn(o), rate: this.dropout, training: s, count: a, dropoutFunc: this.dropoutFunc })); const c = this.dropoutMask, l = (U, Y, j) => !Y || !Y[j] ? U : E(Y[j], U); let u = l(o, c, 0), d = l(o, c, 1), h = l(o, c, 2), p = l(o, c, 3); 0 < this.recurrentDropout && this.recurrentDropout < 1 && this.recurrentDropoutMask == null && (this.recurrentDropoutMask = $s({ ones: () => pn(r), rate: this.recurrentDropout, training: s, count: a, dropoutFunc: this.dropoutFunc })); const f = this.recurrentDropoutMask; let m = l(r, f, 0), g = l(r, f, 1), b = l(r, f, 2), x = l(r, f, 3); const I = 3, [y, C, w, k] = sn(this.kernel.read(), a, I), [S, T, R, G] = this.useBias ? sn(this.bias.read(), a) : [null, null, null, null]; u = this.inputConv(u, y, S, this.padding), d = this.inputConv(d, C, T, this.padding), h = this.inputConv(h, w, R, this.padding), p = this.inputConv(p, k, G, this.padding); const [F, V, z, X] = sn(this.recurrentKernel.read(), a, I); m = this.recurrentConv(m, F), g = this.recurrentConv(g, V), b = this.recurrentConv(b, z), x = this.recurrentConv(x, X); const O = this.recurrentActivation.apply(Q(u, m)), B = this.recurrentActivation.apply(Q(d, g)), K = Q(E(B, i), E(O, this.activation.apply(Q(h, b)))), H = E(this.recurrentActivation.apply(Q(p, x)), this.activation.apply(K)); return [H, H, K] }) } getConfig() { const t = super.getConfig(), e = _$(t, ["units"]), s = { filters: this.filters, kernelSize: this.kernelSize, padding: this.padding, dataFormat: this.dataFormat, dilationRate: this.dilationRate, strides: this.strides }; return Object.assign(Object.assign({}, e), s) } inputConv(t, e, s, o) { const r = qs(t, e, this.strides, o || "valid", this.dataFormat === "channelsFirst" ? "NCHW" : "NHWC", this.dilationRate); return s ? Ln(r, s, this.dataFormat) : r } recurrentConv(t, e) { return qs(t, e, 1, "same", this.dataFormat === "channelsFirst" ? "NCHW" : "NHWC") } } ep.className = "ConvLSTM2DCell", _(ep); class Wb extends Db { constructor(t) { const e = new ep(t); super(Object.assign(Object.assign({}, t), { cell: e })) } static fromConfig(t, e) { return new t(e) } } Wb.className = "ConvLSTM2D", _(Wb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class np extends vt { constructor(t) { super(t), this.rate = Math.max(Math.min(t.rate, 1), 0), this.noiseShape = t.noiseShape, this.seed = t.seed, this.supportsMasking = !0 } getNoiseShape(t) { if (this.noiseShape == null) return this.noiseShape; const e = t.shape, s = []; for (let o = 0; o < this.noiseShape.length; ++o)s.push(this.noiseShape[o] == null ? e[o] : this.noiseShape[o]); return s } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t); if (0 < this.rate && this.rate < 1) { const o = e.training == null ? !1 : e.training, r = this.getNoiseShape(s); return Fi(() => c0(s, this.rate, r, this.seed), () => s, o) } return t }) } getConfig() { const t = { rate: this.rate, noiseShape: this.noiseShape, seed: this.seed }, e = super.getConfig(); return Object.assign(t, e), t } dispose() { return super.dispose() } } np.className = "Dropout", _(np); class Mb extends np { constructor(t) { super(t), this.inputSpec = [{ ndim: 3 }] } getNoiseShape(t) { const e = t.shape; return [e[0], 1, e[2]] } } Mb.className = "SpatialDropout1D", _(Mb); class Fb extends vt { constructor(t) { if (super(t), this.activation = null, this.useBias = !0, this.kernel = null, this.bias = null, this.DEFAULT_KERNEL_INITIALIZER = "glorotNormal", this.DEFAULT_BIAS_INITIALIZER = "zeros", t.batchInputShape == null && t.inputShape == null && t.inputDim != null) { let e = null; t.batchSize != null && (e = t.batchSize), this.batchInputShape = [e, t.inputDim] } this.units = t.units, ge(this.units, "units"), this.activation = Ns(t.activation), t.useBias != null && (this.useBias = t.useBias), this.kernelInitializer = Ht(t.kernelInitializer || this.DEFAULT_KERNEL_INITIALIZER), this.biasInitializer = Ht(t.biasInitializer || this.DEFAULT_BIAS_INITIALIZER), this.kernelConstraint = he(t.kernelConstraint), this.biasConstraint = he(t.biasConstraint), this.kernelRegularizer = _t(t.kernelRegularizer), this.biasRegularizer = _t(t.biasRegularizer), this.activityRegularizer = _t(t.activityRegularizer), this.supportsMasking = !0, this.inputSpec = [{ minNDim: 2 }] } build(t) { t = Nt(t); const e = t[t.length - 1]; this.kernel == null && (this.kernel = this.addWeight("kernel", [e, this.units], null, this.kernelInitializer, this.kernelRegularizer, !0, this.kernelConstraint), this.useBias && (this.bias = this.addWeight("bias", [this.units], null, this.biasInitializer, this.biasRegularizer, !0, this.biasConstraint))), this.inputSpec = [{ minNDim: 2, axes: { [-1]: e } }], this.built = !0 } computeOutputShape(t) { t = Nt(t); const e = t.slice(); return e[e.length - 1] = this.units, e } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t), o = qg(this.activation.getClassName()); let r; return o != null ? r = Bn(s, this.kernel.read(), o, this.bias ? this.bias.read() : null) : (r = Bn(s, this.kernel.read()), this.bias != null && (r = Ln(r, this.bias.read())), this.activation != null && (r = this.activation.apply(r))), r }) } getConfig() { const t = { units: this.units, activation: Ts(this.activation), useBias: this.useBias, kernelInitializer: Qt(this.kernelInitializer), biasInitializer: Qt(this.biasInitializer), kernelRegularizer: Wt(this.kernelRegularizer), biasRegularizer: Wt(this.biasRegularizer), activityRegularizer: Wt(this.activityRegularizer), kernelConstraint: de(this.kernelConstraint), biasConstraint: de(this.biasConstraint) }, e = super.getConfig(); return Object.assign(t, e), t } } Fb.className = "Dense", _(Fb); class Vb extends vt { constructor(t) { t = t || {}, super(t), this.inputSpec = [{ minNDim: 3 }], this.dataFormat = t.dataFormat } computeOutputShape(t) { t = Nt(t); for (const e of t.slice(1)) if (e == null) throw new $(`The shape of the input to "Flatten" is not fully defined (got ${t.slice(1)}). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.`); return [t[0], vs(t, 1)] } call(t, e) { return M(() => { this.invokeCallHook(t, e); let s = mt(t); if (this.dataFormat === "channelsFirst" && s.rank > 1) { const o = [0]; for (let r = 2; r < s.rank; ++r)o.push(r); o.push(1), s = St(s, o) } return LR(s) }) } getConfig() { const t = {}; this.dataFormat != null && (t.dataFormat = this.dataFormat); const e = super.getConfig(); return Object.assign(t, e), t } } Vb.className = "Flatten", _(Vb); class zb extends vt { constructor(t) { super(t), this.supportsMasking = !0, this.activation = Ns(t.activation) } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t); return this.activation.apply(s) }) } getConfig() { const t = { activation: Ts(this.activation) }, e = super.getConfig(); return Object.assign(t, e), t } } zb.className = "Activation", _(zb); class Xb extends vt { constructor(t) { super(t), this.n = t.n, this.inputSpec = [{ ndim: 2 }] } computeOutputShape(t) { return [t[0], this.n, t[1]] } call(t, e) { return M(() => (t = mt(t), $R(t, this.n))) } getConfig() { const t = { n: this.n }, e = super.getConfig(); return Object.assign(t, e), t } } Xb.className = "RepeatVector", _(Xb); class Ab extends vt { constructor(t) { super(t), this.targetShape = t.targetShape; for (let e = 0; e < this.targetShape.length; ++e)this.isUnknown(this.targetShape[e]) && (this.targetShape[e] = null) } isUnknown(t) { return t < 0 || t == null } fixUnknownDimension(t, e) { const s = "Total size of new array must be unchanged.", o = e.slice(); let r = 1, i = null; for (let c = 0; c < o.length; ++c) { const l = o[c]; if (this.isUnknown(l)) if (i === null) i = c; else throw new $("Can only specifiy one unknown dimension."); else r *= l } const a = vs(t); if (i !== null) { if (r === 0 || a % r !== 0) throw new $(s); o[i] = a / r } else if (a !== r) throw new $(s); return o } computeOutputShape(t) { let e = !1; for (let s = 0; s < t.length; ++s)if (this.isUnknown(t[s])) { e = !0; break } return e ? t.slice(0, 1).concat(this.targetShape) : t.slice(0, 1).concat(this.fixUnknownDimension(t.slice(1), this.targetShape)) } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t), o = s.shape, r = o.slice(0, 1).concat(this.fixUnknownDimension(o.slice(1), this.targetShape)); return D(s, r) }) } getConfig() { const t = { targetShape: this.targetShape }, e = super.getConfig(); return Object.assign(t, e), t } } Ab.className = "Reshape", _(Ab); class Ob extends vt { constructor(t) { if (super(t), t.dims == null) throw new Error("Required configuration field `dims` is missing during Permute constructor call."); if (!Array.isArray(t.dims)) throw new Error(`Permute constructor requires \`dims\` to be an Array, but received ${t.dims} instead.`); const e = $n(1, t.dims.length + 1); if (!Rt(t.dims.slice().sort(), e)) throw new Error("Invalid permutation `dims`: " + JSON.stringify(t.dims) + " `dims` must contain consecutive integers starting from 1."); this.dims = t.dims, this.dimsIncludingBatch = [0].concat(this.dims), this.inputSpec = [new ue({ ndim: this.dims.length + 1 })] } computeOutputShape(t) { t = Nt(t); const e = t.slice(); return this.dims.forEach((s, o) => { e[o + 1] = t[s] }), e } call(t, e) { return St(mt(t), this.dimsIncludingBatch) } getConfig() { const t = { dims: this.dims }, e = super.getConfig(); return Object.assign(t, e), t } } Ob.className = "Permute", _(Ob); class Pb extends vt { constructor(t) { super(t ?? {}), this.supportsMasking = !0, t != null ? this.maskValue = t.maskValue == null ? 0 : t.maskValue : this.maskValue = 0 } computeOutputShape(t) { return t } getConfig() { const t = super.getConfig(), e = { maskValue: this.maskValue }; return Object.assign(e, t), e } computeMask(t, e) { const s = mt(t), o = -1; return nd(Gc(s, this.maskValue), o) } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t), o = -1, r = !0, i = nd(Gc(s, this.maskValue), o, r); return E(s, ot(i, s.dtype)) }) } } Pb.className = "Masking", _(Pb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Kb extends vt { constructor(t) { if (super(t), this.embeddings = null, this.DEFAULT_EMBEDDINGS_INITIALIZER = "randomUniform", t.batchInputShape == null && t.inputShape == null) { let e = null; t.batchSize != null && (e = t.batchSize), t.inputLength == null ? this.batchInputShape = [e, null] : this.batchInputShape = [e].concat(Bt(t.inputLength)) } this.inputDim = t.inputDim, ge(this.inputDim, "inputDim"), this.outputDim = t.outputDim, ge(this.outputDim, "outputDim"), this.embeddingsInitializer = Ht(t.embeddingsInitializer || this.DEFAULT_EMBEDDINGS_INITIALIZER), this.embeddingsRegularizer = _t(t.embeddingsRegularizer), this.activityRegularizer = _t(t.activityRegularizer), this.embeddingsConstraint = he(t.embeddingsConstraint), this.maskZero = t.maskZero, this.supportsMasking = t.maskZero, this.inputLength = t.inputLength } build(t) { this.embeddings = this.addWeight("embeddings", [this.inputDim, this.outputDim], this.dtype, this.embeddingsInitializer, this.embeddingsRegularizer, !0, this.embeddingsConstraint), this.built = !0 } warnOnIncompatibleInputShape(t) { } computeMask(t, e) { return M(() => this.maskZero ? (t = mt(t), Gc(t, kt(t))) : null) } computeOutputShape(t) { if (t = Nt(t), this.inputLength == null) return [...t, this.outputDim]; const e = Bt(this.inputLength); if (e.length !== t.length - 1) throw new $(`"inputLength" is ${this.inputLength}, but received input shape has shape ${t}`); { let s = 0; for (let o = 0; o < e.length; ++o) { const r = e[o], i = t[o + 1]; if (r != null && i != null && r !== i) throw new $(`"inputLength" is ${this.inputLength}, but received input shape has shape ${t}`); r == null && (e[s] = i), s++ } } return [t[0], ...e, this.outputDim] } call(t, e) { return M(() => { this.invokeCallHook(t, e); let s = mt(t); s.dtype !== "int32" && (s = Zn(s, "int32")); const o = a0(this.embeddings.read(), D(s, [s.size])); return D(o, Nt(this.computeOutputShape(s.shape))) }) } getConfig() { const t = { inputDim: this.inputDim, outputDim: this.outputDim, embeddingsInitializer: Qt(this.embeddingsInitializer), embeddingsRegularizer: Wt(this.embeddingsRegularizer), activityRegularizer: Wt(this.activityRegularizer), embeddingsConstraint: de(this.embeddingsConstraint), maskZero: this.maskZero, inputLength: this.inputLength }, e = super.getConfig(); return Object.assign(t, e), t } } Kb.className = "Embedding", _(Kb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class go extends vt { constructor(t) { super(t || {}), this.supportsMasking = !0 } mergeFunction(t) { throw new bt } computeElementwiseOpOutputShape(t, e) { if (t == null || e == null) return null; if (t.length < e.length) return this.computeElementwiseOpOutputShape(e, t); if (e.length === 0) return t; const s = t.slice(0, t.length - e.length); for (let o = 0; o < e.length; ++o) { const r = t[t.length - e.length + o], i = e[o]; if (r == null || i == null || r < 0 || i < 0) s.push(null); else if (r === 1) s.push(i); else if (i === 1) s.push(r); else { if (r !== i) throw new $("Operands could not be broadcast together with shapes " + JSON.stringify(t) + " " + JSON.stringify(e)); s.push(r) } } return s } build(t) { if (Array.isArray(t) && !Array.isArray(t[0]) && (t = [Nt(t)]), t = t, t.length < 2) throw new $(`A merge layer should be called on an Array of at least 2 inputs. Got ${t.length} input(s).`); let e = []; for (const r of t) r != null && r[0] !== null && e.push(r[0]); if (e = ws(e), e.length > 1) throw new $(`Can not merge tensors with different batch sizes. Got tensors with shapes: ${JSON.stringify(t)}.`); let s = t[0] == null ? null : t[0].slice(1); for (let r = 1; r < t.length; ++r) { const i = t[r] == null ? null : t[r].slice(1); s = this.computeElementwiseOpOutputShape(s, i) } const o = t.map(r => r.length); t.indexOf(null) === -1 && ws(o).length === 1 ? this.reshapeRequired = !1 : this.reshapeRequired = !0 } call(t, e) { return M(() => { if (t = t, this.reshapeRequired) { const s = [], o = t.map(r => r.rank); if (o.indexOf(null) === -1) { const r = Ss(o); for (let i of t) { const a = i.rank; for (let c = 0; c < r - a; ++c)i = Wi(i, 1); s.push(i) } return this.mergeFunction(s) } else { let r = !1; for (const c of t) { const l = c.rank; if (l == null) { const u = c.shape, d = u[0], h = u.slice(1).concat([d]); let p = D(c, [d].concat(vs(u.slice(1)))); p = St(p, [1, 0]), p = D(p, h), s.push(p), r = !0 } else if (l > 1) { const u = $n(1, l).concat([0]); s.push(St(c, u)), r = !0 } else s.push(c) } let i = this.mergeFunction(s); const a = i.rank; if (r) { if (a == null) { const c = i.shape, l = c.length, u = c[l - 1], d = [u].concat(c.slice(0, c.length - 1)); i = D(St(D(i, [-1, u]), [1, 0]), d) } else if (a > 1) { const c = [a - 1].concat($n(0, a - 1)); i = St(i, c) } } return i } } else return this.mergeFunction(t) }) } computeOutputShape(t) { t = t; let e; t[0] == null ? e = null : e = t[0].slice(1); for (let o = 1; o < t.length; ++o) { const r = t[o] == null ? null : t[o].slice(1); e = this.computeElementwiseOpOutputShape(e, r) } let s = []; for (const o of t) o != null && o[0] !== null && s.push(o[0]); return s = ws(s), s.length === 1 ? e = s.concat(e) : e = [null].concat(e), e } computeMask(t, e) { return M(() => { if (e == null) return null; if (!Array.isArray(e)) throw new $("`mask` should be an Array"); if (!Array.isArray(t)) throw new $("`inputs` should be an Array"); if (e.length !== t.length) throw new $(`The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths (${t.length} vs ${e.length})`); if (e.every(o => o == null)) return null; e = e.map(o => o == null ? o : He(o, 0)); let s = e[0]; for (let o = 1; o < e.length - 1; ++o)s = ss(s, e[o]); return s }) } } class Zb extends go { constructor(t) { super(t) } mergeFunction(t) { return M(() => { let e = t[0].clone(); for (let s = 1; s < t.length; ++s)e = Q(e, t[s]); return e }) } } Zb.className = "Add", _(Zb); class Bb extends go { constructor(t) { super(t) } mergeFunction(t) { return M(() => { let e = t[0].clone(); for (let s = 1; s < t.length; ++s)e = E(e, t[s]); return e }) } } Bb.className = "Multiply", _(Bb); class Hb extends go { constructor(t) { super(t) } mergeFunction(t) { return M(() => { let e = t[0].clone(); for (let s = 1; s < t.length; ++s)e = Q(e, t[s]); return E(1 / t.length, e) }) } } Hb.className = "Average", _(Hb); class _b extends go { constructor(t) { super(t) } mergeFunction(t) { return M(() => { let e = t[0]; for (let s = 1; s < t.length; ++s)e = Is(e, t[s]); return e }) } } _b.className = "Maximum", _(_b); class Ub extends go { constructor(t) { super(t) } mergeFunction(t) { return M(() => { let e = t[0]; for (let s = 1; s < t.length; ++s)e = xd(e, t[s]); return e }) } } Ub.className = "Minimum", _(Ub); class Yb extends go { constructor(t) { super(t), this.DEFAULT_AXIS = -1, t == null && (t = {}), this.axis = t.axis == null ? this.DEFAULT_AXIS : t.axis, this.supportsMasking = !0, this.reshapeRequired = !1 } build(t) { if (!(Array.isArray(t) && Array.isArray(t[0])) || t.length === 1) throw new $("A `Concatenate` layer should be called on a list of at least 2 inputs"); t = t; let e = !0; for (const o of t) if (o != null) { e = !1; break } if (e) return; const s = []; for (let o = 0; o < t.length; ++o) { const r = t[o].slice(); r.splice(this.axis, 1); let i = !1; for (const a of s) if (Rt(a, r)) { i = !0; break } i || s.push(r) } if (s.length > 1) throw new $("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: " + JSON.stringify(t)) } mergeFunction(t) { return M(() => kh(t, this.axis)) } computeOutputShape(t) { if (!(Array.isArray(t) && Array.isArray(t[0]))) throw new $("A `Concatenate` layer should be called on a list of inputs."); const e = t, s = e[0].slice(), o = this.axis < 0 ? s.length + this.axis : this.axis; for (const r of e.slice(1)) { if (s[o] == null || r[o] == null) { s[o] = null; break } s[o] += r[o] } return s } computeMask(t, e) { if (e == null) return null; if (!Array.isArray(e)) throw new $("`mask` should be an array for Concatenate"); if (!Array.isArray(t)) throw new $("`inputs` should be an array for Concatenate"); if (e.length !== t.length) throw new $(`Mismatch in the length of mask (${e.length}) and the legnth of inputs (${t.length})`); return M(() => { let s = !0; if (e.forEach(i => { if (i != null) { s = !1; return } }), s) return null; const o = []; for (let i = 0; i < t.length; ++i)e[i] == null ? o.push(ot(pn(t[i]), "bool")) : e[i].rank < t[i].rank ? o.push(He(e[i], -1)) : o.push(e[i]); const r = Ve(o, this.axis); return Im(r, -1, !1) }) } getConfig() { const t = { axis: this.axis }, e = super.getConfig(); return Object.assign(t, e), t } } Yb.className = "Concatenate", _(Yb); function Hi(n, t) { for (; n < 0;)n += t; return n } function U$(n, t, e) { if (n.shape.length > 3 || t.shape.length > 3) throw new bt("batchDot is not implemented for tensors of 4D or higher rank yet"); if (v(n.shape.length >= 2, () => `batchDot requires the rank of x to be >= 2, but got ${n.shape.length}`), v(n.shape.length >= 2, () => `batchDot requires the rank of y to be >= 2, but got ${t.shape.length}`), typeof e == "number" && (e = [e, e]), n.dtype === "complex64" || t.dtype === "complex64") throw new bt("batchDot is not implemented for complex64-type Tensors yet."); const s = n.shape.length, o = t.shape.length; e == null && (e = [s - 1, o - 2]); const r = e; return M(() => { let i; if (s > o) { i = s - o; const c = []; for (let l = 0; l < i; ++l)c.push(1); t = D(t, t.shape.concat(c)) } else if (o > s) { i = o - s; const c = []; for (let l = 0; l < i; ++l)c.push(1); n = D(n, n.shape.concat(c)) } else i = 0; let a; if (n.shape.length === 2 && t.shape.length === 2) r[0] === r[1] ? a = ut(E(n, t), r[0]) : a = ut(E(St(n, [1, 0]), t), r[1]); else { const c = r[0] !== n.shape.length - 1, l = r[1] === t.shape.length - 1; a = $t(n, t, c, l) } if (i > 0) { let c; s > o ? c = s + o - 3 : c = s - 1; const l = []; for (let u = c; u < c + i; ++u)l.push(u); a = Ti(a, l) } return a.shape.length === 1 && (a = He(a, 1)), a }) } class Qb extends go { constructor(t) { super(t), this.axes = t.axes, this.normalize = t.normalize == null ? !1 : t.normalize, this.supportsMasking = !0, this.reshapeRequired = !1 } build(t) { v(Array.isArray(t) && t.length === 2 && Array.isArray(t[0]) && Array.isArray(t[1]), () => "A `Dot` layer should be called on a list of exactly 2 inputs."); const e = t[0], s = t[1]; if (e.length > 3 || s.length > 3) throw new bt("Dot layer does not support tensors of 4D or higher rank yet."); const o = this.interpretAxes(e, s); if (e[o[0]] !== s[o[1]]) throw new $(`Dimension incompatibility: ${e[o[0]]} !== ${s[o[1]]}`) } mergeFunction(t) { if (t.length !== 2) throw new $(`A \`Dot\` layer must be called on exactly 2 inputs, but received ${t.length} input(s).`); let e = t[0], s = t[1], o; return Array.isArray(this.axes) ? o = this.axes.map((r, i) => Hi(r, t[i].shape.length)) : o = [Hi(this.axes, e.shape.length), Hi(this.axes, s.shape.length)], this.normalize && (e = Yc(e, o[0]), s = Yc(s, o[1])), U$(e, s, o) } interpretAxes(t, e) { let s; return Array.isArray(this.axes) ? s = this.axes : s = [Hi(this.axes, t.length), Hi(this.axes, e.length)], s } computeOutputShape(t) { v(Array.isArray(t) && t.length === 2 && Array.isArray(t[0]) && Array.isArray(t[1]), () => "A `Dot` layer should be called on a list of exactly 2 inputs."); const e = t[0].slice(), s = t[1].slice(); if (e.length > 3 || s.length > 3) throw new bt("Dot layer does not support tensors of 4D or higher rank yet."); const o = this.interpretAxes(e, s); e.splice(o[0], 1), s.splice(o[1], 1), s.splice(0, 1); const r = e.concat(s); return r.length === 1 && r.push(1), r } computeMask(t, e) { return null } getConfig() { const t = { axes: this.axes, normalize: this.normalize }, e = super.getConfig(); return Object.assign(t, e), t } } Qb.className = "Dot", _(Qb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Jb extends vt { constructor(t) { super(t), this.supportsMasking = !0, this.stddev = t.stddev } computeOutputShape(t) { return t } getConfig() { const t = super.getConfig(), e = { stddev: this.stddev }; return Object.assign(e, t), e } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t); return Fi(() => Q(Kc(s.shape, 0, this.stddev), s), () => s, e.training || !1) }) } } Jb.className = "GaussianNoise", _(Jb); class jb extends vt { constructor(t) { super(t), this.supportsMasking = !0, this.rate = t.rate } computeOutputShape(t) { return t } getConfig() { const t = super.getConfig(), e = { rate: this.rate }; return Object.assign(e, t), e } call(t, e) { return M(() => { this.invokeCallHook(t, e); const s = mt(t); return this.rate > 0 && this.rate < 1 ? Fi(() => { const r = Math.sqrt(this.rate / (1 - this.rate)); return E(s, Kc(s.shape, 1, r)) }, () => s, e.training || !1) : s }) } } jb.className = "GaussianDropout", _(jb); class qb extends vt { constructor(t) { super(t), this.supportsMasking = !0, this.rate = t.rate, this.noiseShape = t.noiseShape } _getNoiseShape(t) { return this.noiseShape || mt(t).shape } computeOutputShape(t) { return t } getConfig() { const t = super.getConfig(), e = { rate: this.rate }; return Object.assign(e, t), e } call(t, e) { return M(() => { if (this.rate < 1 && this.rate > 0) { const s = this._getNoiseShape(t); return Fi(() => { const r = mt(t), i = 1.6732632423543772, a = 1.0507009873554805, c = -i * a; let l = to(Lc(s), this.rate); l = Zn(l, "float32"); const u = ((1 - this.rate) * (1 + this.rate * c ** 2)) ** -.5, d = -u * c * this.rate, h = Q(E(r, l), E(Q(l, -1), c)); return Q(E(h, u), d) }, () => mt(t), e.training || !1) } return t }) } } qb.className = "AlphaDropout", _(qb);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function _i(n, t, e, s, o, r = .001) { let i; if (n.rank === 2) i = Ww(n, t, e, s, o, r); else if (n.rank === 3) i = Fw(n, t, e, s, o, r); else if (n.rank === 4) i = zw(n, t, e, s, o, r); else throw new bt(`batchNormalization is not implemented for array of rank ${n.rank} yet`); return i } function Y$(n, t, e, s, o = .001) { return M(() => { const r = yd(n, s), i = r.mean, a = r.variance; return [_i(n, i, a, e, t, o), i, a] }) } function Q$(n, t, e, s, o = .001) { return M(() => { const r = yd(n, s), i = r.mean, a = r.variance, c = []; for (const f of $n(0, n.rank)) s.indexOf(f) !== -1 ? c.push(1) : c.push(n.shape[f]); const l = D(i, c), u = D(a, c), d = t == null ? null : D(t, c), h = e == null ? null : D(e, c); return [_i(n, l, u, h, d, o), i, a] }) } function J$(n, t, e, s, o = .001) { return Rt(s.slice().sort(), $n(0, n.rank - 1)) ? Y$(n, t, e, s, o) : Q$(n, t, e, s, o) } class tx extends vt { constructor(t) { t == null && (t = {}), super(t), this.supportsMasking = !0, this.axis = t.axis == null ? -1 : t.axis, this.momentum = t.momentum == null ? .99 : t.momentum, this.epsilon = t.epsilon == null ? .001 : t.epsilon, this.center = t.center == null ? !0 : t.center, this.scale = t.scale == null ? !0 : t.scale, this.betaInitializer = Ht(t.betaInitializer || "zeros"), this.gammaInitializer = Ht(t.gammaInitializer || "ones"), this.movingMeanInitializer = Ht(t.movingMeanInitializer || "zeros"), this.movingVarianceInitializer = Ht(t.movingVarianceInitializer || "ones"), this.betaConstraint = he(t.betaConstraint), this.gammaConstraint = he(t.gammaConstraint), this.betaRegularizer = _t(t.betaRegularizer), this.gammaRegularizer = _t(t.gammaRegularizer) } build(t) { t = Nt(t); const e = this.axis >= 0 ? this.axis : this.axis + t.length, s = t[e]; if (s == null) throw new $(`Axis ${e} of input tensor should have a defined dimension but the layer received an input with shape ${JSON.stringify(t)}.`); this.inputSpec = [new ue({ ndim: t.length, axes: { [e]: s } })]; const o = [s]; this.scale && (this.gamma = this.addWeight("gamma", o, null, this.gammaInitializer, this.gammaRegularizer, !0, this.gammaConstraint)), this.center && (this.beta = this.addWeight("beta", o, null, this.betaInitializer, this.betaRegularizer, !0, this.betaConstraint)), this.movingMean = this.addWeight("moving_mean", o, null, this.movingMeanInitializer, null, !1), this.movingVariance = this.addWeight("moving_variance", o, null, this.movingVarianceInitializer, null, !1), this.built = !0 } call(t, e) { return M(() => { const s = e.training == null ? !1 : e.training, o = mt(t), r = o.shape, i = r.length, a = $n(0, i), c = this.axis >= 0 ? this.axis : this.axis + i; a.splice(c, 1); const l = lo(1, i); l[c] = r[c]; const u = a.slice(); u.sort(); const d = !Rt(u, $n(0, i).slice(0, i - 1)), h = () => { if (d) { const x = D(this.movingMean.read(), l), I = D(this.movingVariance.read(), l), y = this.center ? D(this.beta.read(), l) : null, C = this.scale ? D(this.gamma.read(), l) : null; return _i(o, x, I, y, C, this.epsilon) } else return _i(o, this.movingMean.read(), this.movingVariance.read(), this.beta == null ? null : this.beta.read(), this.gamma == null ? null : this.gamma.read(), this.epsilon) }; if (!s) return h(); const [p, f, m] = J$(o, this.gamma.read(), this.beta.read(), a, this.epsilon), g = (x, I, y) => { M(() => { const C = 1 - y, w = x.read(), k = E(ft(w, I), C); x.write(ft(w, k)) }) }; return (() => { g(this.movingMean, f, this.momentum), g(this.movingVariance, m, this.momentum) })(), p }) } getConfig() { const t = { axis: this.axis, momentum: this.momentum, epsilon: this.epsilon, center: this.center, scale: this.scale, betaInitializer: Qt(this.betaInitializer), gammaInitializer: Qt(this.gammaInitializer), movingMeanInitializer: Qt(this.movingMeanInitializer), movingVarianceInitializer: Qt(this.movingVarianceInitializer), betaRegularizer: Wt(this.betaRegularizer), gammaRegularizer: Wt(this.gammaRegularizer), betaConstraint: de(this.betaConstraint), gammaConstraint: de(this.gammaConstraint) }, e = super.getConfig(); return Object.assign(t, e), t } } tx.className = "BatchNormalization", _(tx); class ex extends vt { constructor(t) { if (t == null && (t = {}), super(t), this.axis = t.axis == null ? -1 : t.axis, typeof this.axis == "number") { if (!Number.isInteger(this.axis)) throw new Error(`Expected axis to be an integer, but received ${this.axis}`) } else if (Array.isArray(this.axis)) { for (const e of this.axis) if (!Number.isInteger(e)) throw new Error(`Expected axis to be an array of integers, but received ${JSON.stringify(this.axis)}`) } else throw new Error(`Expected axis to be an integer or an array of integers, but received ${JSON.stringify(this.axis)}`); this.epsilon = t.epsilon == null ? .001 : t.epsilon, this.center = t.center == null ? !0 : t.center, this.scale = t.scale == null ? !0 : t.scale, this.betaInitializer = Ht(t.betaInitializer || "zeros"), this.gammaInitializer = Ht(t.gammaInitializer || "ones"), this.betaRegularizer = _t(t.betaRegularizer), this.gammaRegularizer = _t(t.gammaRegularizer), this.supportsMasking = !0 } build(t) { t = Nt(t); const e = t.length; typeof this.axis == "number" && (this.axis = [this.axis]); for (let r = 0; r < this.axis.length; ++r)this.axis[r] < 0 && (this.axis[r] += e); for (const r of this.axis) if (r < 0 || r >= e) throw new Error(`Invalid axis: ${r}`); if (this.axis.length !== ws(this.axis).length) throw new Error(`Found duplicate axes in: ${this.axis}`); const s = this.axis.map(r => t[r]), o = !0; this.scale ? this.gamma = this.addWeight("gamma", s, "float32", this.gammaInitializer, this.gammaRegularizer, o) : this.gamma = null, this.center ? this.beta = this.addWeight("beta", s, "float32", this.betaInitializer, this.betaRegularizer, o) : this.beta = null, this.built = !0 } call(t, e) { const s = mt(t), o = s.shape, r = o.length; return M(() => { let { mean: a, variance: c } = yd(s, this.axis, !0); const l = lo(1, r); for (const m of this.axis) l[m] = o[m]; const u = m => m != null && m.shape.length !== r ? D(m, l) : m; let d = this.scale ? u(this.gamma.read()) : null, h = this.center ? u(this.beta.read()) : null; const p = [], f = []; for (let m = 0; m < r; ++m)this.axis.indexOf(m) !== -1 ? (p.push(o[m]), f.push(1)) : (p.push(1), f.push(o[m])); return a = Nn(a, p), c = Nn(c, p), d != null && (d = Nn(d, f)), h != null && (h = Nn(h, f)), _i(s, a, c, h, d, this.epsilon) }) } getConfig() { const t = { axis: this.axis, epsilon: this.epsilon, center: this.center, scale: this.scale, betaInitializer: Qt(this.betaInitializer), gammaInitializer: Qt(this.gammaInitializer), betaRegularizer: Wt(this.betaRegularizer), gammaRegularizer: Wt(this.gammaRegularizer) }, e = super.getConfig(); return Object.assign(t, e), t } } ex.className = "LayerNormalization", _(ex);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function j$(n, t, e) { return M(() => { if (n.rank !== 4) throw new $(`temporalPadding expects input tensor to be 4-D, but received a ${n.rank}-D tensor.`); if (t == null && (t = [[1, 1], [1, 1]]), t.length !== 2 || t[0].length !== 2 || t[1].length !== 2) throw new $("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers."); if (e == null && (e = Gn()), e !== "channelsLast" && e !== "channelsFirst") throw new $(`Unknown data format: ${e}. Supported data formats are 'channelsLast' and 'channelsFirst.`); let s; return e === "channelsFirst" ? s = [[0, 0], [0, 0], t[0], t[1]] : s = [[0, 0], t[0], t[1], [0, 0]], Id(n, s) }) } class nx extends vt { constructor(t) { if (t == null && (t = {}), super(t), this.dataFormat = t.dataFormat == null ? Gn() : t.dataFormat, t.padding == null) this.padding = [[1, 1], [1, 1]]; else if (typeof t.padding == "number") this.padding = [[t.padding, t.padding], [t.padding, t.padding]]; else { if (t.padding = t.padding, t.padding.length !== 2) throw new $(`ZeroPadding2D expects padding to be a length-2 array, but received a length-${t.padding.length} array.`); let e, s; if (typeof t.padding[0] == "number") e = [t.padding[0], t.padding[0]], s = [t.padding[1], t.padding[1]]; else { if (t.padding = t.padding, t.padding[0].length !== 2) throw new $(`ZeroPadding2D expects height padding to be a length-2 array, but received a length-${t.padding[0].length} array.`); if (e = t.padding[0], t.padding[1].length !== 2) throw new $(`ZeroPadding2D expects width padding to be a length-2 array, but received a length-${t.padding[1].length} array.`); s = t.padding[1] } this.padding = [e, s] } this.inputSpec = [new ue({ ndim: 4 })] } computeOutputShape(t) { t = Nt(t); let e, s; return this.dataFormat === "channelsFirst" ? (t[2] != null && t[2] >= 0 ? e = t[2] + this.padding[0][0] + this.padding[0][1] : e = null, t[3] != null && t[3] >= 0 ? s = t[3] + this.padding[1][0] + this.padding[1][1] : s = null, [t[0], t[1], e, s]) : (t[1] != null && t[1] >= 0 ? e = t[1] + this.padding[0][0] + this.padding[0][1] : e = null, t[2] != null && t[2] >= 0 ? s = t[2] + this.padding[1][0] + this.padding[1][1] : s = null, [t[0], e, s, t[3]]) } call(t, e) { return M(() => j$(mt(t), this.padding, this.dataFormat)) } getConfig() { const t = { padding: this.padding, dataFormat: this.dataFormat }, e = super.getConfig(); return Object.assign(t, e), t } } nx.className = "ZeroPadding2D", _(nx);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function al(n, t, e, s, o, r) { return M(() => { ee(o), e0(r), rn(s), e == null && (e = [1, 1]), s == null && (s = "valid"), o == null && (o = Gn()), r == null && (r = "max"), n = Jh(n, o); let i; const a = s === "same" ? "same" : "valid"; return r === "max" ? i = bd(n, t, e, a) : i = rd(n, t, e, a), o === "channelsFirst" && (i = St(i, [0, 3, 1, 2])), i }) } function sx(n, t, e, s, o, r) { return M(() => { ee(o), e0(r), rn(s), e == null && (e = [1, 1, 1]), s == null && (s = "valid"), o == null && (o = Gn()), r == null && (r = "max"), n = yb(n, o); let i; const a = s === "same" ? "same" : "valid"; return r === "max" ? i = vv(n, t, e, a) : i = Sw(n, t, e, a), o === "channelsFirst" && (i = St(i, [0, 4, 1, 2, 3])), i }) } class ox extends vt { constructor(t) { if (t.poolSize == null && (t.poolSize = 2), super(t), typeof t.poolSize == "number") this.poolSize = [t.poolSize]; else if (Array.isArray(t.poolSize) && t.poolSize.length === 1 && typeof t.poolSize[0] == "number") this.poolSize = t.poolSize; else throw new $(`poolSize for 1D convolutional layer must be a number or an Array of a single number, but received ${JSON.stringify(t.poolSize)}`); if (ge(this.poolSize, "poolSize"), t.strides == null) this.strides = this.poolSize; else if (typeof t.strides == "number") this.strides = [t.strides]; else if (Array.isArray(t.strides) && t.strides.length === 1 && typeof t.strides[0] == "number") this.strides = t.strides; else throw new $(`strides for 1D convolutional layer must be a number or an Array of a single number, but received ${JSON.stringify(t.strides)}`); ge(this.strides, "strides"), this.padding = t.padding == null ? "valid" : t.padding, rn(this.padding), this.inputSpec = [new ue({ ndim: 3 })] } computeOutputShape(t) { t = Nt(t); const e = Wn(t[1], this.poolSize[0], this.padding, this.strides[0]); return [t[0], e, t[2]] } call(t, e) { return M(() => { this.invokeCallHook(t, e), t = Wi(mt(t), 2); const s = this.poolingFunction(mt(t), [this.poolSize[0], 1], [this.strides[0], 1], this.padding, "channelsLast"); return Ti(s, [2]) }) } getConfig() { const t = { poolSize: this.poolSize, padding: this.padding, strides: this.strides }, e = super.getConfig(); return Object.assign(t, e), t } } class rx extends ox { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), al(t, e, s, o, r, "max") } } rx.className = "MaxPooling1D", _(rx); class ix extends ox { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), al(t, e, s, o, r, "avg") } } ix.className = "AveragePooling1D", _(ix); class ax extends vt { constructor(t) { if (t.poolSize == null && (t.poolSize = [2, 2]), super(t), this.poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize], t.strides == null) this.strides = this.poolSize; else if (Array.isArray(t.strides)) { if (t.strides.length !== 2) throw new $(`If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length ${t.strides.length}.`); this.strides = t.strides } else this.strides = [t.strides, t.strides]; ge(this.poolSize, "poolSize"), ge(this.strides, "strides"), this.padding = t.padding == null ? "valid" : t.padding, this.dataFormat = t.dataFormat == null ? "channelsLast" : t.dataFormat, ee(this.dataFormat), rn(this.padding), this.inputSpec = [new ue({ ndim: 4 })] } computeOutputShape(t) { t = Nt(t); let e = this.dataFormat === "channelsFirst" ? t[2] : t[1], s = this.dataFormat === "channelsFirst" ? t[3] : t[2]; return e = Wn(e, this.poolSize[0], this.padding, this.strides[0]), s = Wn(s, this.poolSize[1], this.padding, this.strides[1]), this.dataFormat === "channelsFirst" ? [t[0], t[1], e, s] : [t[0], e, s, t[3]] } call(t, e) { return M(() => (this.invokeCallHook(t, e), this.poolingFunction(mt(t), this.poolSize, this.strides, this.padding, this.dataFormat))) } getConfig() { const t = { poolSize: this.poolSize, padding: this.padding, strides: this.strides, dataFormat: this.dataFormat }, e = super.getConfig(); return Object.assign(t, e), t } } class cx extends ax { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), al(t, e, s, o, r, "max") } } cx.className = "MaxPooling2D", _(cx); class lx extends ax { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), al(t, e, s, o, r, "avg") } } lx.className = "AveragePooling2D", _(lx); class ux extends vt { constructor(t) { if (t.poolSize == null && (t.poolSize = [2, 2, 2]), super(t), this.poolSize = Array.isArray(t.poolSize) ? t.poolSize : [t.poolSize, t.poolSize, t.poolSize], t.strides == null) this.strides = this.poolSize; else if (Array.isArray(t.strides)) { if (t.strides.length !== 3) throw new $(`If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length ${t.strides.length}.`); this.strides = t.strides } else this.strides = [t.strides, t.strides, t.strides]; ge(this.poolSize, "poolSize"), ge(this.strides, "strides"), this.padding = t.padding == null ? "valid" : t.padding, this.dataFormat = t.dataFormat == null ? "channelsLast" : t.dataFormat, ee(this.dataFormat), rn(this.padding), this.inputSpec = [new ue({ ndim: 5 })] } computeOutputShape(t) { t = Nt(t); let e = this.dataFormat === "channelsFirst" ? t[2] : t[1], s = this.dataFormat === "channelsFirst" ? t[3] : t[2], o = this.dataFormat === "channelsFirst" ? t[4] : t[3]; return e = Wn(e, this.poolSize[0], this.padding, this.strides[0]), s = Wn(s, this.poolSize[1], this.padding, this.strides[1]), o = Wn(o, this.poolSize[2], this.padding, this.strides[2]), this.dataFormat === "channelsFirst" ? [t[0], t[1], e, s, o] : [t[0], e, s, o, t[4]] } call(t, e) { return M(() => (this.invokeCallHook(t, e), this.poolingFunction(mt(t), this.poolSize, this.strides, this.padding, this.dataFormat))) } getConfig() { const t = { poolSize: this.poolSize, padding: this.padding, strides: this.strides, dataFormat: this.dataFormat }, e = super.getConfig(); return Object.assign(t, e), t } } class dx extends ux { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), sx(t, e, s, o, r, "max") } } dx.className = "MaxPooling3D", _(dx); class hx extends ux { constructor(t) { super(t) } poolingFunction(t, e, s, o, r) { return ee(r), rn(o), sx(t, e, s, o, r, "avg") } } hx.className = "AveragePooling3D", _(hx); class px extends vt { constructor(t) { super(t), this.inputSpec = [new ue({ ndim: 3 })] } computeOutputShape(t) { return [t[0], t[2]] } call(t, e) { throw new bt } } class fx extends px { constructor(t) { super(t || {}) } call(t, e) { return M(() => { const s = mt(t); return ie(s, 1) }) } } fx.className = "GlobalAveragePooling1D", _(fx); class mx extends px { constructor(t) { super(t || {}) } call(t, e) { return M(() => { const s = mt(t); return Tn(s, 1) }) } } mx.className = "GlobalMaxPooling1D", _(mx); class gx extends vt { constructor(t) { super(t), this.dataFormat = t.dataFormat == null ? "channelsLast" : t.dataFormat, ee(this.dataFormat), this.inputSpec = [new ue({ ndim: 4 })] } computeOutputShape(t) { return t = t, this.dataFormat === "channelsLast" ? [t[0], t[3]] : [t[0], t[1]] } call(t, e) { throw new bt } getConfig() { const t = { dataFormat: this.dataFormat }, e = super.getConfig(); return Object.assign(t, e), t } } class bx extends gx { call(t, e) { return M(() => { const s = mt(t); return this.dataFormat === "channelsLast" ? ie(s, [1, 2]) : ie(s, [2, 3]) }) } } bx.className = "GlobalAveragePooling2D", _(bx); class xx extends gx { call(t, e) { return M(() => { const s = mt(t); return this.dataFormat === "channelsLast" ? Tn(s, [1, 2]) : Tn(s, [2, 3]) }) } } xx.className = "GlobalMaxPooling2D", _(xx);/**
 * @license
 * Copyright 2018 Google LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class yx extends vt { constructor(t) { super(t), this.layer = t.layer } build(t) { this.built = !0 } get trainable() { return this.layer != null ? this.layer.trainable : !1 } set trainable(t) { this.layer != null && (this.layer.trainable = t) } get trainableWeights() { return this.layer.trainableWeights } get nonTrainableWeights() { return this.layer.nonTrainableWeights } get updates() { return this.layer._updates } get losses() { return this.layer.losses } getWeights() { return this.layer.getWeights() } setWeights(t) { this.layer.setWeights(t) } getConfig() { const t = { layer: { className: this.layer.getClassName(), config: this.layer.getConfig() } }, e = super.getConfig(); return Object.assign(t, e), t } setFastWeightInitDuringBuild(t) { super.setFastWeightInitDuringBuild(t), this.layer != null && this.layer.setFastWeightInitDuringBuild(t) } static fromConfig(t, e, s = {}) { const o = e.layer, r = as(o, s); delete e.layer; const i = { layer: r }; return Object.assign(i, e), new t(i) } } class Ix extends yx { constructor(t) { super(t), this.supportsMasking = !0 } build(t) { if (t = Nt(t), t.length < 3) throw new $(`TimeDistributed layer expects an input shape >= 3D, but received input shape ${JSON.stringify(t)}`); this.inputSpec = [{ shape: t }]; const e = [t[0]].concat(t.slice(2)); this.layer.built || (this.layer.build(e), this.layer.built = !0), super.build(t) } computeOutputShape(t) { t = Nt(t); const e = [t[0]].concat(t.slice(2)), s = this.layer.computeOutputShape(e), o = t[1]; return [s[0], o].concat(s.slice(1)) } call(t, e) { return M(() => (t = mt(t), $b((i, a) => [mt(this.layer.call(i, e)), []], t, [], !1, null, null, !1, !0)[1])) } } Ix.className = "TimeDistributed", _(Ix); function q$(n) { ho(SR, "BidirectionalMergeMode", n) } const tG = "concat"; class Cx extends yx { constructor(t) { super(t); const e = t.layer.getConfig(), s = {}; s.className = t.layer.getClassName(), s.config = e, this.forwardLayer = as(s), e.goBackwards = e.goBackwards !== !0; const o = {}; if (o.className = t.layer.getClassName(), o.config = e, this.backwardLayer = as(o), this.forwardLayer.name = "forward_" + this.forwardLayer.name, this.backwardLayer.name = "backward_" + this.backwardLayer.name, this.mergeMode = t.mergeMode === void 0 ? tG : t.mergeMode, q$(this.mergeMode), t.weights) throw new bt("weights support is not implemented for Bidirectional layer yet."); this._stateful = t.layer.stateful, this.returnSequences = t.layer.returnSequences, this.returnState = t.layer.returnState, this.supportsMasking = !0, this._trainable = !0, this.inputSpec = t.layer.inputSpec, this.numConstants = null } get trainable() { return this._trainable } set trainable(t) { this._trainable = t, this.forwardLayer != null && (this.forwardLayer.trainable = t), this.backwardLayer != null && (this.backwardLayer.trainable = t) } getWeights() { return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights()) } setWeights(t) { const e = t.length, s = Math.floor(e / 2); this.forwardLayer.setWeights(t.slice(0, s)), this.backwardLayer.setWeights(t.slice(s)) } computeOutputShape(t) { let e = this.forwardLayer.computeOutputShape(t); Array.isArray(e) && Array.isArray(e[0]) || (e = [e]), e = e; let s, o, r; return this.returnState && (r = e.slice(1)), s = e[0], s = s, this.mergeMode === "concat" ? (s[s.length - 1] *= 2, o = [s]) : this.mergeMode == null ? o = [s, s.slice()] : o = [s], this.returnState ? this.mergeMode == null ? o.concat(r).concat(r.slice()) : [s].concat(r).concat(r.slice()) : ze(o) } apply(t, e) { let s = e == null ? null : e.initialState, o = e == null ? null : e.constants; e == null && (e = {}); const r = Rb(t, s, o, this.numConstants); if (t = r.inputs, s = r.initialState, o = r.constants, Array.isArray(t) && (s = t.slice(1), t = t[0]), (s == null || s.length === 0) && o == null) return super.apply(t, e); const i = [], a = []; if (s != null) { const l = s.length; if (l % 2 > 0) throw new $("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs."); e.initialState = s, i.push(...s); const u = s.map(d => new ue({ shape: d.shape })); this.forwardLayer.stateSpec = u.slice(0, l / 2), this.backwardLayer.stateSpec = u.slice(l / 2), a.push(...u) } if (o != null) throw new bt("Support for constants in Bidirectional layers is not implemented yet."); const c = i[0] instanceof Hn; for (const l of i) if (l instanceof Hn !== c) throw new $("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors"); if (c) { const l = [t].concat(i), u = this.inputSpec.concat(a), d = this.inputSpec; this.inputSpec = u; const h = super.apply(l, e); return this.inputSpec = d, h } else return super.apply(t, e) } call(t, e) { return M(() => { const s = e.initialState; let o, r; if (s == null) o = this.forwardLayer.call(t, e), r = this.backwardLayer.call(t, e); else { const c = s.slice(0, s.length / 2), l = s.slice(s.length / 2); o = this.forwardLayer.call(t, Object.assign(e, { initialState: c })), r = this.backwardLayer.call(t, Object.assign(e, { initialState: l })) } let i; this.returnState && (Array.isArray(o) && (i = o.slice(1).concat(r.slice(1))), o = o[0], r = r[0]), this.returnSequences && (r = oo(r, 1)); let a; return this.mergeMode === "concat" ? a = kh([o, r]) : this.mergeMode === "sum" ? a = Q(o, r) : this.mergeMode === "ave" ? a = E(.5, Q(o, r)) : this.mergeMode === "mul" ? a = E(o, r) : this.mergeMode == null && (a = [o, r]), this.returnState ? this.mergeMode == null ? a.concat(i) : [a].concat(i) : a }) } resetStates(t) { this.forwardLayer.resetStates(), this.backwardLayer.resetStates() } build(t) { po(this.forwardLayer.name, () => { this.forwardLayer.build(t) }), po(this.backwardLayer.name, () => { this.backwardLayer.build(t) }), this.built = !0 } computeMask(t, e) { Array.isArray(e) && (e = e[0]); let s; if (this.returnSequences ? this.mergeMode == null ? s = [e, e] : s = e : this.mergeMode == null ? s = [null, null] : s = null, this.returnState) { const r = this.forwardLayer.states.map(i => null); return Array.isArray(s) ? s.concat(r).concat(r) : [s].concat(r).concat(r) } else return s } get trainableWeights() { return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights) } get nonTrainableWeights() { return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights) } setFastWeightInitDuringBuild(t) { super.setFastWeightInitDuringBuild(t), this.forwardLayer != null && this.forwardLayer.setFastWeightInitDuringBuild(t), this.backwardLayer != null && this.backwardLayer.setFastWeightInitDuringBuild(t) } getConfig() { const t = { mergeMode: this.mergeMode }, e = super.getConfig(); return Object.assign(t, e), t } static fromConfig(t, e) { const s = as(e.layer); if (delete e.layer, e.numConstants != null) throw new bt("Deserialization of a Bidirectional layer with numConstants present is not supported yet."); const o = e; return o.layer = s, new t(o) } } Cx.className = "Bidirectional", _(Cx);/**
 * @license
 * Copyright 2022 CodeSmith LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class wx extends vt { constructor(t) { super(t), this.scale = t.scale, t.offset ? this.offset = t.offset : this.offset = 0 } getConfig() { const t = { scale: this.scale, offset: this.offset }, e = super.getConfig(); return Object.assign(t, e), t } call(t, e) { return M(() => (t = mt(t), t.dtype !== "float32" && (t = Zn(t, "float32")), Q(E(t, this.scale), this.offset))) } } wx.className = "Rescaling", _(wx);/**
 * @license
 * Copyright 2022 CodeSmith LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const { resizeBilinear: eG, cropAndResize: nG } = io; class vx extends vt { constructor(t) { super(t), this.height = t.height, this.width = t.width } centerCrop(t, e, s, o, r, i, a, c) { return M(() => { let l, u = !1; const d = e / i, h = s / a, p = (o + e) / i, f = (r + s) / a, m = [d, h, p, f], g = []; t.rank === 3 ? (u = !0, l = os([t])) : l = t; for (let C = 0; C < l.shape[0]; C++)g.push(m); const b = qe(g, [g.length, 4]), x = ki(0, g.length, 1, "int32"), y = nG(l, b, x, [o, r], "nearest"); return Zn(u ? mt(ro(y)) : y, c) }) } upsize(t, e, s, o) { return M(() => { const r = eG(t, [e, s]); return Zn(r, o) }) } call(t, e) { return M(() => { const s = mt(t), o = s.dtype, r = s.shape, i = r[r.length - 3], a = r[r.length - 2]; let c = 0; i !== this.height && (c = Math.floor((i - this.height) / 2)); let l = 0; return a !== this.width && (l = Math.floor((a - this.width) / 2), l === 0 && (l = 1)), c >= 0 && l >= 0 ? this.centerCrop(s, c, l, this.height, this.width, i, a, o) : this.upsize(t, this.height, this.width, o) }) } getConfig() { const t = { height: this.height, width: this.width }, e = super.getConfig(); return Object.assign(t, e), t } computeOutputShape(t) { t = Nt(t); const e = t.length - 3, s = t.length - 2; return t[e] = this.height, t[s] = this.width, t } } vx.className = "CenterCrop", _(vx);/**
 * @license
 * Copyright 2022 CodeSmith LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */function sG(n, t, e, s) { let o = mt(n); if (o.dtype !== "int32" && (o = Zn(o, "int32")), t === "int") return o; const r = o.shape; if (o.rank === 0 && (o = He(o, -1)), t === "oneHot" && o.shape[o.shape.length - 1] !== 1 && (o = He(o, -1)), o.rank > 2) throw new $(`When outputMode is not int, maximum output rank is 2 Received outputMode ${t} and input shape ${r} which would result in output rank ${o.rank}.`); const i = ["multiHot", "oneHot"].includes(t), a = o; let c; if (typeof s < "u" && t === "count" ? c = Tm(a, s, e, i) : c = Tm(a, [], e, i), t !== "tfIdf") return c; if (s) return E(c, s); throw new $("When outputMode is 'tfIdf', weights must be provided.") }/**
 * @license
 * Copyright 2022 CodeSmith LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */class Sx extends vt {
        constructor(t) { super(t), this.numTokens = t.numTokens, t.outputMode ? this.outputMode = t.outputMode : this.outputMode = "multiHot" } getConfig() { const t = { numTokens: this.numTokens, outputMode: this.outputMode }, e = super.getConfig(); return Object.assign(t, e), t } computeOutputShape(t) { return t = Nt(t), t == null ? [this.numTokens] : this.outputMode === "oneHot" && t[t.length - 1] !== 1 ? (t.push(this.numTokens), t) : (t[t.length - 1] = this.numTokens, t) } call(t, e) {
            return M(() => {
                t = mt(t), t.dtype !== "int32" && (t = Zn(t, "int32")); let s; if (typeof e.countWeights < "u") {
                    if (this.outputMode !== "count") throw new $(`countWeights is not used when outputMode !== count.
              Received countWeights=${e.countWeights}`); s = mt(e.countWeights)
                } const o = Tn(t), r = Nc(t), i = nn(this.numTokens, o).bufferSync().get(0), a = to(r, 0).bufferSync().get(0); if (!(i && a)) throw new $(`Input values must be between 0 < values <= numTokens with numTokens=${this.numTokens}`); return sG(t, this.outputMode, this.numTokens, s)
            })
        }
    } Sx.className = "CategoryEncoding", _(Sx);/**
 * @license
 * Copyright 2022 CodeSmith LLC
 *
 * Use of this source code is governed by an MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT.
 * =============================================================================
 */const oG = ["bilinear", "nearest"], kx = new Set(oG); class Tx extends vt { constructor(t) { if (super(t), this.height = t.height, this.width = t.width, t.interpolation) if (kx.has(t.interpolation)) this.interpolation = t.interpolation; else throw new $(`Invalid interpolation parameter: ${t.interpolation} is not implemented`); else this.interpolation = "bilinear"; this.cropToAspectRatio = !!t.cropToAspectRatio } computeOutputShape(t) { t = Nt(t); const e = t[2]; return [this.height, this.width, e] } getConfig() { const t = { height: this.height, width: this.width, interpolation: this.interpolation, cropToAspectRatio: this.cropToAspectRatio }, e = super.getConfig(); return Object.assign(t, e), t } call(t, e) { return M(() => { const s = [this.height, this.width]; if (this.interpolation === "bilinear") return io.resizeBilinear(t, s, !this.cropToAspectRatio); if (this.interpolation === "nearest") return io.resizeNearestNeighbor(t, s, !this.cropToAspectRatio); throw new Error(`Interpolation is ${this.interpolation} but only ${[...kx]} are supported`) }) } } Tx.className = "Resizing", _(Tx);/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */A().registerFlag("KEEP_INTERMEDIATE_TENSORS", () => !1, n => { n && console.warn("Keep intermediate tensors is ON. This will print the values of all intermediate tensors during model inference. Not all models support this mode. For details, check e2e/benchmarks/ model_config.js. This significantly impacts performance.") });/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * =============================================================================
 */var Nx; (function (n) { n[n.DT_INVALID = 0] = "DT_INVALID", n[n.DT_FLOAT = 1] = "DT_FLOAT", n[n.DT_DOUBLE = 2] = "DT_DOUBLE", n[n.DT_INT32 = 3] = "DT_INT32", n[n.DT_UINT8 = 4] = "DT_UINT8", n[n.DT_INT16 = 5] = "DT_INT16", n[n.DT_INT8 = 6] = "DT_INT8", n[n.DT_STRING = 7] = "DT_STRING", n[n.DT_COMPLEX64 = 8] = "DT_COMPLEX64", n[n.DT_INT64 = 9] = "DT_INT64", n[n.DT_BOOL = 10] = "DT_BOOL", n[n.DT_QINT8 = 11] = "DT_QINT8", n[n.DT_QUINT8 = 12] = "DT_QUINT8", n[n.DT_QINT32 = 13] = "DT_QINT32", n[n.DT_BFLOAT16 = 14] = "DT_BFLOAT16", n[n.DT_QINT16 = 15] = "DT_QINT16", n[n.DT_QUINT16 = 16] = "DT_QUINT16", n[n.DT_UINT16 = 17] = "DT_UINT16", n[n.DT_COMPLEX128 = 18] = "DT_COMPLEX128", n[n.DT_HALF = 19] = "DT_HALF", n[n.DT_RESOURCE = 20] = "DT_RESOURCE", n[n.DT_VARIANT = 21] = "DT_VARIANT", n[n.DT_UINT32 = 22] = "DT_UINT32", n[n.DT_UINT64 = 23] = "DT_UINT64", n[n.DT_FLOAT_REF = 101] = "DT_FLOAT_REF", n[n.DT_DOUBLE_REF = 102] = "DT_DOUBLE_REF", n[n.DT_INT32_REF = 103] = "DT_INT32_REF", n[n.DT_UINT8_REF = 104] = "DT_UINT8_REF", n[n.DT_INT16_REF = 105] = "DT_INT16_REF", n[n.DT_INT8_REF = 106] = "DT_INT8_REF", n[n.DT_STRING_REF = 107] = "DT_STRING_REF", n[n.DT_COMPLEX64_REF = 108] = "DT_COMPLEX64_REF", n[n.DT_INT64_REF = 109] = "DT_INT64_REF", n[n.DT_BOOL_REF = 110] = "DT_BOOL_REF", n[n.DT_QINT8_REF = 111] = "DT_QINT8_REF", n[n.DT_QUINT8_REF = 112] = "DT_QUINT8_REF", n[n.DT_QINT32_REF = 113] = "DT_QINT32_REF", n[n.DT_BFLOAT16_REF = 114] = "DT_BFLOAT16_REF", n[n.DT_QINT16_REF = 115] = "DT_QINT16_REF", n[n.DT_QUINT16_REF = 116] = "DT_QUINT16_REF", n[n.DT_UINT16_REF = 117] = "DT_UINT16_REF", n[n.DT_COMPLEX128_REF = 118] = "DT_COMPLEX128_REF", n[n.DT_HALF_REF = 119] = "DT_HALF_REF", n[n.DT_RESOURCE_REF = 120] = "DT_RESOURCE_REF", n[n.DT_VARIANT_REF = 121] = "DT_VARIANT_REF", n[n.DT_UINT32_REF = 122] = "DT_UINT32_REF", n[n.DT_UINT64_REF = 123] = "DT_UINT64_REF" })(Nx || (Nx = {})); var Rx; (function (n) { (function (t) { t[t.LEGACY = 0] = "LEGACY", t[t.V1 = 1] = "V1", t[t.V2 = 2] = "V2" })(n.CheckpointFormatVersion || (n.CheckpointFormatVersion = {})) })(Rx || (Rx = {}));/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * =============================================================================
 */var $x; (function (n) { n[n.FAIL = 0] = "FAIL", n[n.SHORTEST = 1] = "SHORTEST", n[n.LONGEST = 2] = "LONGEST" })($x || ($x = {}));/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function it(n, t) { Array.isArray(n) || (n = [n]), n.forEach(e => { e != null && v(e.dtype !== "complex64", () => `${t} does not support complex64 tensors in the CPU backend.`) }) }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rG = Um; class cl extends Al {
        constructor() { super(), this.blockSize = 48, this.firstUse = !0, this.data = new ef(this, Ft()) } nextDataId() { return cl.nextDataId++ } write(t, e, s) {
            this.firstUse && (this.firstUse = !1, A().get("IS_NODE") && Qe(`
============================
Hi, looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, visit https://github.com/tensorflow/tfjs-node for more details. 
============================`)); const o = { id: this.nextDataId() }; return this.data.set(o, { values: t, dtype: s, refCount: 1 }), o
        } makeTensorInfo(t, e, s) { let o; if (e === "string" && s != null && s.length > 0 && br(s[0])) { const r = s.map(i => fs(i)); o = this.write(r, t, e) } else o = this.write(s, t, e); return { dataId: o, shape: t, dtype: e } } refCount(t) { return this.data.has(t) ? this.data.get(t).refCount : 0 } incRef(t) { const e = this.data.get(t); e.refCount++ } decRef(t) { if (this.data.has(t)) { const e = this.data.get(t); e.refCount-- } } move(t, e, s, o, r) { this.data.set(t, { values: e, dtype: o, refCount: r }) } numDataIds() { return this.data.numDataIds() } async read(t) { return this.readSync(t) } readSync(t) { const { dtype: e, complexTensorInfos: s } = this.data.get(t); if (e === "complex64") { const o = this.readSync(s.real.dataId), r = this.readSync(s.imag.dataId); return rs(o, r) } return PI(this.data.get(t).values, e) } bufferSync(t) { const e = this.readSync(t.dataId); if (t.dtype === "string") try { const s = e.map(o => ms(o)); return Ct(t.shape, t.dtype, s) } catch { throw new Error("Failed to decode encoded string bytes into utf-8") } return Ct(t.shape, t.dtype, e) } makeOutput(t, e, s) { return Ft().makeTensorFromTensorInfo(this.makeTensorInfo(e, s, t), this) } disposeData(t, e = !1) { if (this.data.has(t)) { if (this.data.get(t).refCount--, !e && this.data.get(t).refCount > 0) return !1; const { complexTensorInfos: s } = this.data.get(t); s != null && (this.disposeData(s.real.dataId, !0), this.disposeData(s.imag.dataId, !0)), this.data.delete(t) } return !0 } disposeIntermediateTensorInfo(t) { this.disposeData(t.dataId) } async time(t) { const e = Me(); return t(), { kernelMs: Me() - e } } memory() { return { unreliable: !0, reasons: ["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."] } } where(t) { it([t], "where"); const e = this.readSync(t.dataId); return rG(t.shape, e) } dispose() { } floatPrecision() { return 32 } epsilon() { return super.epsilon() }
    } cl.nextDataId = 0;/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gx(n) { const t = new Float32Array(n.length); for (let e = 0; e < n.length; ++e)t[e] = Math.abs(n[e]); return t } const iG = { kernelName: ma, backendName: "cpu", kernelFunc: n => { const { x: t } = n.inputs, e = n.backend; it(t, "abs"); let s = new Float32Array(Z(t.shape)); const o = e.data.get(t.dataId).values; return s = Gx(o), e.makeOutput(s, t.shape, t.dtype) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ae(n) { return (t, e, s, o, r) => { const i = gt(t, e), a = i.length, c = ct(i), l = Z(i), u = xe(r, l), d = t.length, h = e.length, p = ct(t), f = ct(e), m = Oo(t, i), g = Oo(e, i); if (m.length + g.length === 0) for (let b = 0; b < u.length; ++b)u[b] = n(s[b % s.length], o[b % o.length]); else for (let b = 0; b < u.length; ++b) { const x = Go(b, a, c), I = x.slice(-d); m.forEach(k => I[k] = 0); const y = Vn(I, d, p), C = x.slice(-h); g.forEach(k => C[k] = 0); const w = Vn(C, h, f); u[b] = n(s[y], o[w]) } return [u, i] } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ue(n) { const { inputs: t, backend: e } = n, { real: s, imag: o } = t, r = e.data.get(s.dataId).values, i = e.data.get(o.dataId).values, a = e.makeTensorInfo(s.shape, "complex64"), c = e.data.get(a.dataId); return c.complexTensorInfos = { real: e.makeTensorInfo(s.shape, "float32", r), imag: e.makeTensorInfo(o.shape, "float32", i) }, a } const aG = { kernelName: ou, backendName: "cpu", kernelFunc: Ue };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ll(n, t, e = "float32") { if (e === "complex64") { const o = ll(n, t, "float32"), r = ll(n, t, "float32"); return Ue({ inputs: { real: o, imag: r }, backend: n }) } const s = Se(Z(t), e); return n.makeTensorInfo(t, e, s) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Un(n) { const { inputs: t, backend: e } = n, { x: s } = t; return e.incRef(s.dataId), { dataId: s.dataId, shape: s.shape, dtype: s.dtype } } const cG = { kernelName: Xr, backendName: "cpu", kernelFunc: Un };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bo(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = e.data.get(s.dataId).complexTensorInfos.real, r = e.data.get(o.dataId).values; return e.makeTensorInfo(o.shape, o.dtype, r) } const lG = { kernelName: $u, backendName: "cpu", kernelFunc: bo };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Lx(n, t, e, s) { if (s === "int32") { const o = Int32Array.from(n); return [t, "int32", o] } if (s === "bool") { const o = Bs([0], e), [r, i] = ae((a, c) => a !== c ? 1 : 0)(t, [], n, o, "bool"); return [i, "bool", r] } throw new Error(`Error in Cast: failed to cast ${e} to ${s}`) } function Gs(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { dtype: r } = s; if (r === "complex64") { if (o.dtype === "complex64") return Un({ inputs: { x: o }, backend: e }); const u = ll(e, o.shape, o.dtype), d = Gs({ inputs: { x: o }, backend: e, attrs: { dtype: "float32" } }), h = Ue({ inputs: { real: d, imag: u }, backend: e }); return e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(d), h } if (o.dtype === "complex64") { const u = bo({ inputs: { input: o }, backend: e }), d = Gs({ inputs: { x: u }, backend: e, attrs: { dtype: r } }); return e.disposeIntermediateTensorInfo(u), d } if (!of(o.dtype, r)) { const u = Un({ inputs: { x: o }, backend: e }); return { dataId: u.dataId, shape: u.shape, dtype: r } } const i = e.data.get(o.dataId).values, [a, c, l] = Lx(i, o.shape, o.dtype, r); return e.makeTensorInfo(a, c, l) } const uG = { kernelName: Tr, backendName: "cpu", kernelFunc: Gs };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function be(n, t, e, s) { return e == null ? ({ inputs: o, backend: r }) => { const { a: i, b: a } = o, c = r; it([i, a], n); const l = c.data.get(i.dataId).values, u = c.data.get(a.dataId).values, d = i.dtype === "string" ? co(l) : l, h = i.dtype === "string" ? co(u) : u, p = s || i.dtype, [f, m] = t(i.shape, a.shape, d, h, p); return c.makeTensorInfo(m, p, f) } : ({ inputs: o, backend: r }) => { const { a: i, b: a } = o, c = r; if (i.dtype === "complex64" || a.dtype === "complex64") { const l = Gs({ inputs: { x: i }, backend: c, attrs: { dtype: "complex64" } }), u = c.data.get(l.dataId), d = u.complexTensorInfos.real, h = u.complexTensorInfos.imag, p = c.data.get(d.dataId).values, f = c.data.get(h.dataId).values, m = Gs({ inputs: { x: a }, backend: c, attrs: { dtype: "complex64" } }), g = c.data.get(m.dataId), b = g.complexTensorInfos.real, x = g.complexTensorInfos.imag, I = c.data.get(b.dataId).values, y = c.data.get(x.dataId).values, [C, w, k] = e(i.shape, a.shape, p, f, I, y), S = c.makeTensorInfo(k, "float32", C), T = c.makeTensorInfo(k, "float32", w), R = Ue({ inputs: { real: S, imag: T }, backend: c }); return c.disposeIntermediateTensorInfo(l), c.disposeIntermediateTensorInfo(m), c.disposeIntermediateTensorInfo(S), c.disposeIntermediateTensorInfo(T), R } else { const l = c.data.get(i.dataId).values, u = c.data.get(a.dataId).values, d = s || i.dtype, [h, p] = t(i.shape, a.shape, l, u, d); return c.makeTensorInfo(p, d, h) } } } function sp(n) { return (t, e, s, o, r, i) => { const a = gt(t, e), c = Z(a), l = a.length, u = ct(a), d = xe("float32", c), h = xe("float32", c), p = Oo(t, a), f = Oo(e, a), m = rs(s, o), g = rs(r, i), b = t.length, x = ct(t), I = e.length, y = ct(e); if (p.length + f.length === 0) for (let C = 0; C < d.length; C++) { const w = C % m.length, k = C % g.length, S = n(m[w * 2], m[w * 2 + 1], g[k * 2], g[k * 2 + 1]); d[C] = S.real, h[C] = S.imag } else for (let C = 0; C < d.length; C++) { const w = Go(C, l, u), k = w.slice(-b); p.forEach(F => k[F] = 0); const S = Vn(k, b, x), T = w.slice(-I); f.forEach(F => T[F] = 0); const R = Vn(T, I, y), G = n(m[S * 2], m[S * 2 + 1], g[R * 2], g[R * 2 + 1]); d[C] = G.real, h[C] = G.imag } return [d, h, a] } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ex = ae((n, t) => n + t), dG = sp((n, t, e, s) => ({ real: n + e, imag: t + s })), qo = be(Lo, Ex, dG), hG = { kernelName: Lo, backendName: "cpu", kernelFunc: qo };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function op(n, t, e, s, o) { const r = Z(s), i = Se(o, e); for (let a = 0; a < n.length; a++) { const c = n[a]; if (c < 0) throw new Error("Input x must be non-negative!"); c >= o || (r > 0 ? i[c] += t[a] : i[c] += 1) } return i } function Dx(n, t, e, s = !1) { const o = n.shape[0], r = n.shape[1], i = Ct([o, e], t.dtype); for (let a = 0; a < o; a++)for (let c = 0; c < r; c++) { const l = n.get(a, c); if (l < 0) throw new Error("Input x must be non-negative!"); l >= e || (s ? i.set(1, a, l) : t.size > 0 ? i.set(i.get(a, l) + t.get(a, c), a, l) : i.set(i.get(a, l) + 1, a, l)) } return i }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ls(n) { return (t, e, s) => { const o = xe(e, t.length); for (let r = 0; r < t.length; ++r)o[r] = n(t[r], s); return o } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Lt(n, t, e) { return ({ inputs: s, attrs: o, backend: r }) => { const { x: i } = s; if (it(i, n), i.dtype === "string" || e === "string") throw new Error("unaryKernelFunc does not support string input/output"); const a = r, c = a.data.get(i.dataId).values, l = Z(i.shape), u = e || i.dtype, d = ne(u, l); for (let h = 0; h < l; ++h)d[h] = t(c[h], o); return a.makeTensorInfo(i.shape, u, d) } } function tr(n, t, e) { return ({ inputs: s, attrs: o, backend: r }) => { const { x: i } = s; if (it(i, n), i.dtype === "string" || e === "string") throw new Error("unaryKernelFunc does not support string input/output"); const a = r, c = a.data.get(i.dataId).values, l = e || i.dtype, u = t(c, l, o); return a.makeTensorInfo(i.shape, l, u) } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Wx = Ls(n => Math.ceil(n)), pG = tr(Nr, Wx), fG = { kernelName: Nr, backendName: "cpu", kernelFunc: pG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Mx(n, t, e, s) { const o = ne(e, Z(t)); if (s && e !== "string") { let r = 0; n.forEach(i => { const a = Z(i.shape); o.set(i.vals, r), r += a }) } else { let r = 0; n.forEach(i => { const a = e === "string" ? co(i.vals) : i.vals; let c = 0; for (let l = 0; l < i.shape[0]; ++l) { const u = l * t[1] + r; for (let d = 0; d < i.shape[1]; ++d)o[u + d] = a[c++] } r += i.shape[1] }) } return o }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Fx = ae((n, t) => n === t ? 1 : 0), Vx = be(Ga, Fx, null, "bool"), mG = { kernelName: Ga, backendName: "cpu", kernelFunc: Vx };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zx = Ls(n => Math.exp(n)), Xx = tr(Wr, zx, "float32"), gG = { kernelName: Wr, backendName: "cpu", kernelFunc: Xx };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ax = Ls(n => Math.expm1(n)), bG = tr(Mr, Ax), xG = { kernelName: Mr, backendName: "cpu", kernelFunc: bG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ox = Ls(n => Math.floor(n)), yG = tr(Fr, Ox), IG = { kernelName: Fr, backendName: "cpu", kernelFunc: yG };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Px(n, t, e, s, o, r, i, a, c) { const l = Ct([s, r], e); for (let u = 0; u < s; u++) { const d = []; let h = 0; for (let p = 0; p < o; p++) { const f = n[u * o + p]; h += f * i[p], d.push(f) } if (h < 0 || h >= c / r) throw new Error(`Invalid indices: ${d} does not index into ${a}`); for (let p = 0; p < r; p++)l.values[u * r + p] = t.get(...t.indexToLoc(h * r + p)) } return l }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Kx(n, t, e) { const s = Ct(e, n.dtype); for (let o = 0; o < s.size; ++o) { const i = s.indexToLoc(o).slice(), a = i[0], c = i[2], l = t.locToIndex([a, c]); i[2] = t.values[l]; const u = n.locToIndex(i); 0 <= u && u < n.values.length && (s.values[o] = n.values[u]) } return s }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Zx = ae((n, t) => n > t ? 1 : 0), CG = be(Wa, Zx, null, "bool"), wG = { kernelName: Wa, backendName: "cpu", kernelFunc: CG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Bx = ae((n, t) => n >= t ? 1 : 0), vG = be(zr, Bx, null, "bool"), SG = { kernelName: zr, backendName: "cpu", kernelFunc: vG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Hx = ae((n, t) => n < t ? 1 : 0), kG = be(Fa, Hx, null, "bool"), TG = { kernelName: Fa, backendName: "cpu", kernelFunc: kG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _x = ae((n, t) => n <= t ? 1 : 0), NG = be(Va, _x, null, "bool"), RG = { kernelName: Va, backendName: "cpu", kernelFunc: NG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ux(n, t, e) { const s = (t - n) / (e - 1), o = Se(e, "float32"); o[0] = n; for (let r = 1; r < o.length; r++)o[r] = o[r - 1] + s; return o }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Yx = Ls(n => Math.log(n)), $G = tr(Kr, Yx), GG = { kernelName: Kr, backendName: "cpu", kernelFunc: $G };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Qx(n, t, e, s) { const o = xe(s, Z(e)); for (let r = 0; r < o.length; ++r) { const i = r * t; let a = n[i]; for (let c = 0; c < t; ++c) { const l = n[i + c]; (Number.isNaN(l) || l > a) && (a = l) } o[r] = a } return o }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Jx = ae((n, t) => Math.max(n, t)), LG = be(Br, Jx), EG = { kernelName: Br, backendName: "cpu", kernelFunc: LG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const jx = ae((n, t) => Math.min(n, t)), DG = be(Hr, jx), WG = { kernelName: Hr, backendName: "cpu", kernelFunc: DG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rp = ae((n, t) => n * t), MG = sp((n, t, e, s) => ({ real: n * e - t * s, imag: n * s + t * e })), ul = be(Ur, rp, MG), FG = { kernelName: Ur, backendName: "cpu", kernelFunc: ul };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qx(n, t, e) { const s = ps(-1, e); return rp([], t, s, n, e) } function VG(n) { const { inputs: t, backend: e } = n, { x: s } = t; it(s, "neg"); const o = e.data.get(s.dataId).values, [r, i] = qx(o, s.shape, s.dtype); return e.makeTensorInfo(i, s.dtype, r) } const zG = { kernelName: Ua, backendName: "cpu", kernelFunc: VG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ty = ae((n, t) => n !== t ? 1 : 0), XG = be(Ya, ty, null, "bool"), AG = { kernelName: Ya, backendName: "cpu", kernelFunc: XG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ip(n, t, e, s, o) { const r = t.length, i = Z(t), a = ct(t), c = ct(o), l = xe(e, Z(o)); for (let u = 0; u < i; ++u) { const d = Go(u, r, a), h = new Array(d.length); for (let f = 0; f < h.length; f++)h[f] = d[s[f]]; const p = Vn(h, r, c); l[p] = n[u] } return l }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ae(n) { const { inputs: t, attrs: e, backend: s } = n, { x: o } = t, { perm: r } = e; it(o, "transpose"); const i = o.shape.length, a = new Array(i); for (let d = 0; d < a.length; d++)a[d] = o.shape[r[d]]; const c = s.data.get(o.dataId).values, l = ip(c, o.shape, o.dtype, r, a); return { dataId: s.write(l, a, o.dtype), shape: a, dtype: o.dtype } } const OG = { kernelName: Eo, backendName: "cpu", kernelFunc: Ae };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ey(n, t, e, s) { const [o, r] = fe(n, s), i = Ze(t, "int32"), a = Se(Z(o), i), c = Z(r); for (let l = 0; l < a.length; ++l) { const u = l * c; let d = 1; for (let h = 0; h < c; ++h)d *= e[u + h]; a[l] = d } return { outVals: a, outShape: o, outDtype: i } } function PG(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; it(o, "prod"); const a = o.shape.length, c = It(r, o.shape), l = Yt(c, a); let u = c, d = o; const h = []; l != null && (d = Ae({ inputs: { x: o }, backend: e, attrs: { perm: l } }), h.push(d), u = te(u.length, a)); const p = e.data.get(d.dataId).values, { outVals: f, outShape: m, outDtype: g } = ey(d.shape, d.dtype, p, u); let b = m; return i && (b = oe(m, c)), h.forEach(x => e.disposeIntermediateTensorInfo(x)), e.makeTensorInfo(b, g, f) } const KG = { kernelName: ec, backendName: "cpu", kernelFunc: PG };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ZG(n, t, e) { n.forEach((s, o) => { if (s < 0 || s >= e) { const r = Go(o, t.length, ct(t)).join(","); throw new Error(`indices[${r}] = ${s} is not in [0, ${e})`) } }) } function BG(n, t) { for (let e = 0; e < n.length; ++e) { const s = n[e], o = e === n.length - 1 ? t : n[e + 1].length; if (s.length === 0) throw new Error("Ragged splits may not be empty"); if (s[0] < 0) throw new Error("Ragged splits must be non-negative"); if (s[s.length - 1] > o) throw new Error("Ragged splits must not point past values"); for (let r = 1; r < s.length; ++r)if (s[r - 1] > s[r]) throw new Error("Ragged splits must be sorted in ascending order") } } function HG(n, t, e, s) { const o = []; let r = 0; const i = t.length - 1 + e.length, a = new Array(i).fill(null).map(() => [0]); BG(e, s); let c = 1; for (let l = 0; l < t.length - 1; ++l) { c *= t[l]; const u = t[l + 1]; for (let d = 1; d < c + 1; ++d)a[l].push(d * u) } for (let l = 0; l < n.length; ++l) { let u = n[l], d = n[l] + 1; for (let h = 0; h < e.length; ++h) { const p = e[h], f = h + t.length - 1; if (f >= 0) { const m = a[f], g = m[m.length - 1] - p[u]; for (let b = u; b < d; ++b)a[f].push(p[b + 1] + g) } u = p[u], d = p[d] } d !== u && (o.push([u, d]), r += d - u) } return { outSplits: a, valueSlices: o, numValues: r } } function _G(n) { const t = []; for (let e = 0; e < n.length; ++e) { const s = n[e].length, o = ne("int32", s); t.push(o), n[e].forEach((r, i) => o[i] = r) } return t } function ny(n, t) { const e = n.slice(0, t); for (; e.length < t;)e.push(1); for (let s = t; s < n.length; s++)e[t - 1] *= n[s]; return e } function UG(n, t, e, s, o, r) { const i = ny(t, 2)[1], a = ny(r, 2)[1]; let c = 0; for (const l of e) for (let u = l[0]; u < l[1]; ++u) { for (let d = 0; d < s; ++d)o[c * a + d] = n[u * i + d]; ++c } } function YG(n, t, e, s, o) { const r = t.slice(); r[0] = o; const i = ne(e, Z(r)), a = n.length, c = a === 0 ? 0 : a / t[0]; return UG(n, t, s, c, i, r), [i, r] } function sy(n, t, e, s, o, r, i, a) { if (n.length === 0) throw new Error("paramsNestedSplits must be non empty"); if (t[0].length === 0) throw new Error("Split tensors must not be scalars"); const c = t[0][0] - 1; if (ZG(r, i, c), s.length === 0) throw new Error("params.rank must be nonzero"); const l = s[0], { outSplits: u, valueSlices: d, numValues: h } = HG(r, i, n, l), p = _G(u), f = YG(e, s, o, d, h); return [p, f[0], f[1]] }/**
 * @license
 * Copyright 2022 Google LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oy = 2147483647; function ry(n, t, e, s, o, r, i) { if (t.length > 1) throw new Error("starts must be a scalar or vector"); if (o.length > 1) throw new Error("limits must be a scalar or vector"); if (i.length > 1) throw new Error("deltas must be a scalar or vector"); const a = t.length === 0, c = o.length === 0, l = i.length === 0, u = []; a || u.push(t[0]), c || u.push(o[0]), l || u.push(i[0]); for (let g = 1; g < u.length; ++g)if (u[g] !== u[g - 1]) throw new Error("starts, limits, and deltas must have the same shape"); const d = u.length === 0 ? 1 : u[0], h = ne("int32", d + 1); h[0] = 0; for (let g = 0; g < d; ++g) { const b = a ? n[0] : n[g], x = c ? s[0] : s[g], I = l ? r[0] : r[g]; if (I === 0) throw new Error("Requires delta != 0"); let y; if (I > 0 && x < b || I < 0 && x > b) y = 0; else if (y = Math.ceil(Math.abs((x - b) / I)), y > oy) throw new Error(`Requires ((limit - start) / delta) <= ${oy}`); h[g + 1] = h[g] + y } const p = h[d], f = ne(e, p); let m = 0; for (let g = 0; g < d; ++g) { const b = h[g + 1] - h[g]; let x = a ? n[0] : n[g]; const I = l ? r[0] : r[g]; for (let y = 0; y < b; ++y)f[m++] = x, x += I } return [h, f] }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */var yn = Rn; class dl { constructor(t, e, s, o, r, i, a, c, l, u) { this.shape = t, this.shapeShape = e, this.values = s, this.valuesShape = o, this.valuesDType = r, this.defaultValue = i, this.defaultValueShape = a, this.rowPartitionValues = c, this.rowPartitionValuesShapes = l, this.rowPartitionTypes = bg(u), this.raggedRank = xg(this.rowPartitionTypes) } getRowPartitionTypeByDimension(t) { return this.rowPartitionTypes[0] === yn.FIRST_DIM_SIZE ? this.rowPartitionTypes[t + 1] : this.rowPartitionTypes[t] } getRowPartitionTensor(t) { return this.rowPartitionTypes[0] === yn.FIRST_DIM_SIZE ? this.rowPartitionValues[t + 1] : this.rowPartitionValues[t] } getMaxWidth(t) { const e = this.getRowPartitionTensor(t - 1); switch (this.getRowPartitionTypeByDimension(t - 1)) { case yn.VALUE_ROWIDS: return dl.getMaxWidthValueRowID(e); case yn.ROW_SPLITS: return dl.getMaxWidthRowSplit(e); default: throw new Error(`Cannot handle partition type ${yn[this.getRowPartitionTypeByDimension(t - 1)]}`) } } static getMaxWidthRowSplit(t) { const e = t.length; if (e === 0 || e === 1) return 0; let s = 0; for (let o = 0; o < e - 1; ++o) { const r = t[o + 1] - t[o]; r > s && (s = r) } return s } static getMaxWidthValueRowID(t) { const e = t.length; if (e === 0) return 0; let s = 0, o = t[0], r = 0; for (let i = 1; i < e; ++i) { const a = t[i]; a !== o && (o = a, r = Math.max(i - s, r), s = i) } return Math.max(e - s, r) } tensorShapeFromTensor(t, e, s = !0) { if (e.length === 0) { if (t[0] === -1) return []; throw new Error("The only valid scalar shape tensor is the fully unknown shape specified as -1.") } return ay(t, s) } calculateOutputSize(t) { const e = this.valuesShape, s = this.defaultValueShape; yg(s, e); const o = this.tensorShapeFromTensor(this.shape, this.shapeShape), i = gg(this.raggedRank, o, e); i[0] < 0 && (i[0] = t); for (let a = 1; a <= this.raggedRank; ++a)i[a] < 0 && (i[a] = this.getMaxWidth(a)); return i } calculateFirstParentOutputIndex(t, e, s) { const o = Math.min(t, s), r = []; let i = 0; for (let a = 0; a < o; ++a, i += e)r.push(i); for (let a = o; a < t; ++a)r.push(-1); return v(r.length === t, () => "Final length of result must be equal to firstDimension."), r } calculateOutputIndexRowSplit(t, e, s, o) { const r = t.length, i = []; for (let a = 0; a < r - 1; ++a) { const c = t[a + 1] - t[a]; let l = Math.min(o, c), u = e[a]; u === -1 && (l = 0); for (let d = 0; d < l; ++d)i.push(u), u += s; for (let d = 0; d < c - l; ++d)i.push(-1) } if (r > 0 && i.length !== t[r - 1]) throw new Error("Invalid row split size."); return i } calculateOutputIndexValueRowID(t, e, s, o) { const r = t.length, i = []; if (r === 0) return []; let a = 0, c = t[0]; if (c >= e.length) throw new Error(`Got currentValueRowId=${c}, which is not less than ${e.length}`); let l = e[c]; i.push(l); for (let u = 1; u < r; ++u) { const d = t[u]; if (d === c) l >= 0 && (++a, a < o ? l += s : l = -1); else { if (a = 0, c = d, d >= e.length) throw new Error(`Got nextValueRowId=${d} which is not less than ${e.length}`); l = e[d] } i.push(l) } if (i.length !== t.length) throw new Error("Invalid row ids."); return i } calculateOutputIndex(t, e, s, o) { const r = this.getRowPartitionTensor(t), i = this.getRowPartitionTypeByDimension(t); switch (i) { case yn.VALUE_ROWIDS: return this.calculateOutputIndexValueRowID(r, e, s, o); case yn.ROW_SPLITS: if (r.length - 1 > e.length) throw new Error(`Row partition size is greater than output size: ${r.length - 1} > ${e.length}`); return this.calculateOutputIndexRowSplit(r, e, s, o); default: throw new Error(`Unsupported partition type: ${yn[i]}`) } } getFirstDimensionSize() { const t = this.rowPartitionValues[0]; if (this.rowPartitionTypes.length === 0) throw new Error("No row_partition_types given."); const e = this.rowPartitionTypes[0]; switch (e) { case yn.FIRST_DIM_SIZE: return t[0]; case yn.VALUE_ROWIDS: throw new Error("Cannot handle VALUE_ROWIDS in first dimension."); case yn.ROW_SPLITS: return this.rowPartitionValuesShapes[0][0] - 1; default: throw new Error(`Cannot handle type ${yn[e]}`) } } compute() { if (this.rowPartitionValues[0].length <= 0) throw new Error("Invalid first partition input. Tensor requires at least one element."); const e = this.getFirstDimensionSize(), s = this.calculateOutputSize(e), o = new Array(this.raggedRank + 1); o[o.length - 1] = 1; for (let c = o.length - 2; c >= 0; --c)o[c] = o[c + 1] * s[c + 1]; const r = ay(s, !1), i = ne(this.valuesDType, Z(r)); if (o[0] * s[0] > 0) { let c = this.calculateFirstParentOutputIndex(e, o[0], s[0]); for (let l = 1; l <= this.raggedRank; ++l)c = this.calculateOutputIndex(l - 1, c, o[l], s[l]); this.setOutput(this.raggedRank, c, i, r) } return [r, i] } setOutput(t, e, s, o) { if (s.length === 0) return; const r = this.values, i = s; let a = o.slice(); a = a.slice(t + 1); const c = Z(a), l = e.length; let u = this.defaultValue; if (u.length !== c && u.length !== 1) { const f = this.defaultValueShape; M(() => { const m = D(u, f); u = vi(m, a).dataSync() }) } let d = 0, h = 0, p = 0; for (let f = 0; f <= l; ++f) { let m = f < l ? e[f] : -1; if (m === p) { ++p; continue } if (h < p) { const g = r.subarray(d * c), b = i.subarray(h * c), x = (p - h) * c; iy(b, g, x) } if (f >= l) { const g = s.length; m = Math.floor(g / c) } if (m > p) if (this.defaultValue.length === 1) i.subarray(p * c, m * c).fill(this.defaultValue[0]), p = m; else for (; m > p;) { const g = i.slice(p * c); iy(g, u, c), ++p } m < 0 ? (d = f + 1, h = p) : (d = f, h = p, p = h + 1) } } } function iy(n, t, e) { for (let s = 0; s < e; s++)n[s] = t[s] } function ay(n, t) { const e = []; for (let s of n) { if (s < 0) { if (!t) throw new Error(`Dimension ${s} must be >= 0`); if (s < -1) throw new Error(`Dimension ${s} must be >= -1`); s = -1 } e.push(s) } return e } function cy(n, t, e, s, o, r, i, a, c, l) { return new dl(n, t, e, s, o, r, i, a, c, l).compute() }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ly(n, t, e, s) { const o = n === t, r = n < t && e < 0, i = t < n && e > 1; if (o || r || i) return Se(0, s); const a = Math.abs(Math.ceil((t - n) / e)), c = Se(a, s); t < n && e === 1 && (e = -1), c[0] = n; for (let l = 1; l < c.length; l++)c[l] = c[l - 1] + e; return c }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uy = Ls(n => 1 / Math.sqrt(n)), QG = tr(ti, uy), JG = { kernelName: ti, backendName: "cpu", kernelFunc: QG };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function er(n, t, e, s, o, r, i, a, c, l) { const u = [s / o, o], d = n.values, h = t.values; if (s === 0) return Ct(e, t.dtype); const p = Ct(u, t.dtype); typeof c == "string" || typeof c == "number" ? p.values.fill(c) : typeof c == "boolean" && p.values.fill(+c); for (let f = 0; f < r; f++) { const m = []; let g = 0; for (let b = 0; b < i; b++) { const x = d[f * i + b]; m.push(x), g += x * a[b] } if (g < 0 || g >= s / o) throw new Error(`Invalid indices: ${m} does not index into ${e}`); for (let b = 0; b < o; b++)l ? p.values[g * o + b] += h[f * o + b] : p.values[g * o + b] = t.rank === 0 ? h[0] : h[f * o + b] } return p }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const jG = Ls(n => 1 / (1 + Math.exp(-n))), dy = Lt(ri, n => 1 / (1 + Math.exp(-n))), qG = { kernelName: ri, backendName: "cpu", kernelFunc: dy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hy(n, t, e, s, o) { const r = Yd(s, t, e), i = Z(e), a = ct(s); if (r) { const d = Qd(t, a); return o === "string" ? n.slice(d, d + i) : n.subarray(d, d + i) } const c = o === "string" ? co(n) : n, l = Ct(s, o, c), u = Ct(e, o); for (let d = 0; d < u.size; ++d) { const h = u.indexToLoc(d), p = h.map((f, m) => f + t[m]); u.set(l.get(...p), ...h) } return o === "string" ? Og(u.values) : u.values } function xo(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { begin: r, size: i } = s; it(o, "slice"); const [a, c] = Wc(o, r, i); _d(o, a, c); const l = e.data.get(o.dataId).values, u = hy(l, a, c, o.shape, o.dtype); return e.makeTensorInfo(c, o.dtype, u) } const tL = { kernelName: ac, backendName: "cpu", kernelFunc: xo };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function py(n, t, e, s, o, r, i) { const a = t[0], c = r[0], l = new Array(c), u = new Array(a), d = t[1]; if (c === 0) { if (a !== 0) throw new Error(Rg(a)); const g = ne(e, 0), b = ne(o, 0); return [g, [0, d], b, l, u] } let h = !0, p = 0; const f = new Array(c).fill(0); for (let g = 0; g < a; ++g) { const b = n[g * d]; if (b < 0) throw new Error($g(g, b)); if (b >= c) throw new Error(Gg(g, b, c)); ++f[b], h = h && b >= p, p = b } let m = !0; for (let g = 0; g < c; ++g) { const b = f[g] === 0; l[g] = b, m = m && !b, f[g] = Math.max(f[g], 1), g > 0 && (f[g] += f[g - 1]) } if (m && h) { const g = n, b = s; for (let x = 0; x < a; ++x)u[x] = x; return [g, [a, d], b, l, u] } else { const g = f[c - 1], b = ne(e, g * d), x = ne(o, g), I = new Array(c).fill(0); for (let y = 0; y < a; ++y) { const C = n[y * d], w = I[C], k = (C === 0 ? 0 : f[C - 1]) + w; I[C]++; for (let S = 0; S < d; ++S)b[k * d + S] = n[y * d + S]; x[k] = s[y], u[y] = k } for (let y = 0; y < c; ++y)if (I[y] === 0) { const w = y === 0 ? 0 : f[y - 1]; b[w * d + 0] = y; for (let k = 1; k < d; ++k)b[w * d + k] = 0; x[w] = i } return [b, [g, d], x, l, u] } }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fy(n, t, e, s, o) { const r = Z(s), i = t[0], a = o.length, c = []; let l = 1, u = -1; for (let g = 0; g < a; ++g) { const b = o[g]; if (b === -1) { if (u !== -1) throw new Error(Lg(u, g)); u = g, c.push(1) } else { if (b < 0) throw new Error(Eg(g, b)); l *= b, c.push(b) } } if (u !== -1) { if (l <= 0) throw new Error(Dg()); const g = Math.trunc(r / l); if (l * g !== r) throw new Error(Wg(s, c)); c[u] = g } if (Z(c) !== r) throw new Error(Mg(s, c)); const h = s.length, p = []; if (h > 0) { p[h - 1] = 1; for (let g = h - 2; g >= 0; --g)p[g] = p[g + 1] * s[g + 1] } const f = []; if (a > 0) { f[a - 1] = 1; for (let g = a - 2; g >= 0; --g)f[g] = f[g + 1] * c[g + 1] } const m = ne(e, i * a); for (let g = 0; g < i; ++g) { let b = 0; for (let x = 0; x < h; ++x)b += n[g * h + x] * p[x]; for (let x = 0; x < a; ++x)m[g * a + x] = Math.trunc(b / f[x]), b %= f[x] } return [m, [i, a], c] }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ap(n, t, e, s, o, r = !1, i = 0) { const a = s.length, c = [t[0], n.length / t[0]], l = c[1], d = a > 0 ? o[a - 1] + 1 : 0; if (d < 0) throw new Error(bh()); const h = t.slice(); h[0] = d; const p = h.reduce((I, y) => I * y, 1), f = ne(e, p); if (a === 0) return d > 0 && f.fill(i), [f, h]; if (d <= 0) throw new Error(bh()); let m = 0, g = 1, b = 0, x = o[m]; for (; ;) { let I = 0; if (g < a) { if (I = o[g], x === I) { ++g; continue } if (x >= I) throw new Error(Fg()) } if (x < 0 || x >= d) throw new Error(Vg(x, d)); x > b && f.fill(i, b * l, x * l); for (let y = m; y < g; ++y) { const C = s[y]; if (C < 0 || C >= c[0]) throw new Error(zg(y, s[y], c[0])); for (let w = 0; w < l; w++)f[x * l + w] += n[C * l + w] } if (r) for (let y = 0; y < l; y++)f[x * l + y] /= g - m; if (m = g, ++g, b = x + 1, x = I, g > a) break } return b < d && f.fill(i, b * l, d * l), [f, h] }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const eL = Ls(n => Math.sqrt(n)), nL = Lt(ai, n => Math.sqrt(n)), sL = { kernelName: ai, backendName: "cpu", kernelFunc: nL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const my = ae((n, t) => { const e = n - t; return e * e }), oL = be(ci, my), rL = { kernelName: ci, backendName: "cpu", kernelFunc: oL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function gy(n, t, e, s) { const o = Ct(n, t.dtype); for (let r = 0; r < o.size; r++) { const i = o.indexToLoc(r), a = new Array(i.length); for (let c = 0; c < a.length; c++)a[c] = i[c] * e[c] + s[c]; o.set(t.get(...a), ...i) } return o }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class iL { constructor(t, e, s, o, r, i) { this.separator = fs(t), this.nGramWidths = e, this.leftPad = fs(s), this.rightPad = fs(o), this.padWidth = r, this.preserveShort = i } getPadWidth(t) { return Math.min(this.padWidth < 0 ? t - 1 : this.padWidth, t - 1) } getNumNGrams(t, e) { const s = this.getPadWidth(e); return Math.max(0, t + 2 * s - e + 1) } createNGrams(t, e, s, o, r, i) { for (let a = 0; a < r; ++a) { const c = this.getPadWidth(i), l = Math.max(0, c - a), u = Math.max(0, c - (r - (a + 1))), d = i - (l + u), h = e + (l > 0 ? 0 : a - c); let p = 0; p += l * this.leftPad.length; for (let x = 0; x < d; ++x)p += t[h + x].length; p += u * this.rightPad.length; const f = l + u + d - 1; p += f * this.separator.length, s[o + a] = new Uint8Array(p); const m = s[o + a]; let g = 0; const b = x => x.forEach(I => m[g++] = I); for (let x = 0; x < l; ++x)b(this.leftPad), b(this.separator); for (let x = 0; x < d - 1; ++x)b(t[h + x]), b(this.separator); if (d > 0) { b(t[h + d - 1]); for (let x = 0; x < u; ++x)b(this.separator), b(this.rightPad) } else { for (let x = 0; x < u - 1; ++x)b(this.rightPad), b(this.separator); b(this.rightPad) } } } compute(t, e) { const s = t.length, o = e.length; if (o > 0) { let c = e[0]; if (c !== 0) throw new Error(`First split value must be 0, got ${c}`); for (let l = 1; l < o; ++l) { let u = e[l] >= c; if (u = u && e[l] <= s, !u) throw new Error(`Invalid split value ${e[l]}, must be in [${c}, ${s}]`); c = e[l] } if (c !== s) throw new Error(`Last split value must be data size. Expected ${s}, got ${c}`) } const r = o - 1, i = ne("int32", o); if (s === 0 || o === 0) { const c = new Array(s); for (let l = 0; l <= r; ++l)i[l] = 0; return [c, i] } i[0] = 0; for (let c = 1; c <= r; ++c) { const l = e[c] - e[c - 1]; let u = 0; this.nGramWidths.forEach(d => { u += this.getNumNGrams(l, d) }), this.preserveShort && l > 0 && u === 0 && (u = 1), i[c] = i[c - 1] + u } const a = new Array(i[r]); for (let c = 0; c < r; ++c) { const l = e[c]; let u = i[c]; if (this.nGramWidths.forEach(d => { const h = e[c + 1] - e[c], p = this.getNumNGrams(h, d); this.createNGrams(t, l, a, u, p, d), u += p }), this.preserveShort && u === i[c]) { const d = e[c + 1] - e[c]; if (d === 0) continue; const h = d + 2 * this.padWidth, p = 1; this.createNGrams(t, l, a, u, p, h) } } return [a, i] } } function by(n, t, e, s, o, r, i, a) { return new iL(e, s, o, r, i, a).compute(n, t) }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aL(n, t, e, s) { if (!n.length) return; if (t.length === 0) { for (let r = 0; r < n.length; ++r)s.push(n.subarray(r, r + 1)); return } if (t.length === 1) { const r = t[0]; let i = n.indexOf(r); for (; i !== -1;) { const a = n.subarray(0, i); (!e || a.length !== 0) && s.push(a), n = n.subarray(i + 1), i = n.indexOf(r) } (!e || n.length !== 0) && s.push(n); return } let o = 0; for (let r = 0; r < n.length + 1; r++)if (r === n.length || t.indexOf(n[r]) !== -1) { const i = n.subarray(o, r); (!e || i.length !== 0) && s.push(i), o = r + 1 } } function xy(n, t, e) { const s = n.length, o = []; let r = 0, i = 0; const a = new Array(s); for (let h = 0; h < s; ++h) { const p = o.length; aL(n[h], t, e, o); const f = o.length - p; a[h] = f, r += f, i = Math.max(i, f) } const c = ne("int32", r * 2), l = new Array(r), u = [s, i]; let d = 0; for (let h = 0; h < s; ++h)for (let p = 0; p < a[h]; ++p)c[d * 2] = h, c[d * 2 + 1] = p, l[d] = o[d], ++d; return [c, l, u] }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yy(n, t) { const e = ne("int32", n.length); for (let s = 0; s < n.length; ++s)e[s] = aC(n[s]).modulo(t).getLowBitsUnsigned(); return e }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Iy = ae((n, t) => n - t), cL = sp((n, t, e, s) => ({ real: n - e, imag: t - s })), cp = be(li, Iy, cL), lL = { kernelName: li, backendName: "cpu", kernelFunc: cp };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Cy(n, t) { const e = new Array(n.rank); for (let o = 0; o < e.length; o++)e[o] = n.shape[o] * t[o]; const s = Ct(e, n.dtype); for (let o = 0; o < s.values.length; ++o) { const r = s.indexToLoc(o), i = new Array(n.rank); for (let c = 0; c < i.length; c++)i[c] = r[c] % n.shape[c]; const a = n.locToIndex(i); s.values[o] = n.values[a] } return s }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ui = (n, t) => { const e = t.value - n.value; return e === 0 ? n.index - t.index : e }; function wy(n, t, e = 0, s = n.length - 1) { for (; s > e;) { if (s - e > 600) { const a = s - e + 1, c = t - e + 1, l = Math.log(a), u = .5 * Math.exp(2 * l / 3), d = .5 * Math.sqrt(l * u * (a - u) / a) * Math.sign(c - a / 2), h = Math.max(e, Math.floor(t - c * u / a + d)), p = Math.min(s, Math.floor(t + (a - c) * u / a + d)); wy(n, t, h, p) } const o = n[t]; let r = e, i = s; for (No(n, e, t), Ui(n[s], o) > 0 && No(n, e, s); r < i;) { for (No(n, r, i), r++, i--; Ui(n[r], o) < 0;)r = r + 1; for (; Ui(n[i], o) > 0;)i = i - 1 } Ui(n[e], o) === 0 ? No(n, e, i) : (i = i + 1, No(n, i, s)), i <= t && (e = i + 1), t <= i && (s = i - 1) } } function vy(n, t, e, s, o) { const r = t[t.length - 1], [i, a] = [n.length / r, r], c = xe(e, i * s), l = xe("int32", i * s); for (let d = 0; d < i; d++) { const h = d * a, p = n.subarray(h, h + a); let f = new Array(p.length); p.forEach((x, I) => f[I] = { value: x, index: I }), s < f.length && (wy(f, s), f = f.slice(0, s)), o && f.sort(Ui); const m = d * s, g = c.subarray(m, m + s), b = l.subarray(m, m + s); for (let x = 0; x < s; x++)g[x] = f[x].value, b[x] = f[x].index } const u = t.slice(); return u[u.length - 1] = s, [Ct(u, e, c), Ct(u, "int32", l)] }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Sy(n, t, e, s) { const o = It(t, e)[0], r = [1, e[0], 1]; for (let f = 0; f < o; f++)r[0] *= e[f]; r[1] = e[o]; for (let f = o + 1; f < e.length; f++)r[2] *= e[f]; const i = {}, a = new Int32Array(e[o]), c = new ke(r, s, n), l = [], u = r[0] === 1 && r[2] === 1; for (let f = 0; f < e[o]; f++) { let m; if (u) m = n[f].toString(); else { const g = []; for (let b = 0; b < r[0]; b++)for (let x = 0; x < r[2]; x++)g.push(c.get(b, f, x)); m = g.join(",") } if (i[m] !== void 0) a[f] = i[m]; else { const g = Object.keys(i).length; i[m] = g, a[f] = g, l.push(f) } } const d = r.slice(); d[1] = Object.keys(i).length; const h = new ke(d, s); l.forEach((f, m) => { for (let g = 0; g < r[0]; g++)for (let b = 0; b < r[2]; b++)h.set(c.get(g, f, b), g, m, b) }); const p = e.slice(); return p[o] = d[1], { outputValues: h.values, outputShape: p, indices: a } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uL = Object.freeze(Object.defineProperty({ __proto__: null, addImpl: Ex, bincountImpl: op, bincountReduceImpl: Dx, castImpl: Lx, ceilImpl: Wx, concatImpl: Mx, equalImpl: Fx, expImpl: zx, expm1Impl: Ax, floorImpl: Ox, gatherNdImpl: Px, gatherV2Impl: Kx, greaterEqualImpl: Bx, greaterImpl: Zx, lessEqualImpl: _x, lessImpl: Hx, linSpaceImpl: Ux, logImpl: Yx, maxImpl: Qx, maximumImpl: Jx, minimumImpl: jx, multiplyImpl: rp, negImpl: qx, notEqualImpl: ty, prodImpl: ey, raggedGatherImpl: sy, raggedRangeImpl: ry, raggedTensorToTensorImpl: cy, rangeImpl: ly, rsqrtImpl: uy, scatterImpl: er, sigmoidImpl: jG, simpleAbsImpl: Gx, sliceImpl: hy, sparseFillEmptyRowsImpl: py, sparseReshapeImpl: fy, sparseSegmentReductionImpl: ap, sqrtImpl: eL, squaredDifferenceImpl: my, stridedSliceImpl: gy, stringNGramsImpl: by, stringSplitImpl: xy, stringToHashBucketFastImpl: yy, subImpl: Iy, tileImpl: Cy, topKImpl: vy, transposeImpl: ip, uniqueImpl: Sy }, Symbol.toStringTag, { value: "Module" }));/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */xm("cpu", () => new cl, 1);/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ky = Lt(Er, n => n >= 0 ? n : Math.exp(n) - 1), dL = { kernelName: Er, backendName: "cpu", kernelFunc: ky };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ty(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { alpha: r } = s; it([o], "leakyRelu"); const i = Z(o.shape), a = e.data.get(o.dataId).values, c = xe("float32", i); for (let l = 0; l < a.length; l++)c[l] = a[l] < 0 ? r * a[l] : a[l]; return e.makeTensorInfo(o.shape, "float32", c) } const hL = { kernelName: Ma, backendName: "cpu", kernelFunc: Ty };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const pL = ae((n, t) => n < 0 ? t * n : n); function Ny(n) { const { inputs: t, backend: e } = n, { x: s, alpha: o } = t; it([s, o], "prelu"); const r = e.data.get(s.dataId).values, i = e.data.get(o.dataId).values, [a, c] = pL(s.shape, o.shape, r, i, "float32"); return e.makeTensorInfo(c, "float32", a) } const fL = { kernelName: tc, backendName: "cpu", kernelFunc: Ny };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Ry = Lt(Jr, n => Math.max(0, n)), mL = { kernelName: Jr, backendName: "cpu", kernelFunc: Ry };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const $y = Lt(jr, n => Math.min(Math.max(0, n), 6)), gL = { kernelName: jr, backendName: "cpu", kernelFunc: $y };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hl(n, t, e, s, o) { if (e === "linear") return Un({ inputs: { x: t }, backend: n }); if (e === "relu") return Ry({ inputs: { x: t }, backend: n }); if (e === "elu") return ky({ inputs: { x: t }, backend: n }); if (e === "relu6") return $y({ inputs: { x: t }, backend: n }); if (e === "prelu") return Ny({ inputs: { x: t, alpha: s }, backend: n }); if (e === "leakyrelu") return Ty({ inputs: { x: t }, backend: n, attrs: { alpha: o } }); if (e === "sigmoid") return dy({ inputs: { x: t }, backend: n }); throw new Error(`Activation ${e} has not been implemented for the CPU backend.`) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function zt(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { shape: r } = s, i = Z(o.shape), a = sf(r, i), c = Z(a); v(i === c, () => `The new shape (${a}) has ${c} elements and the old shape (${o.shape}) has ${i} elements. The new shape and old shape must have the same number of elements.`), e.incRef(o.dataId); const l = e.data.get(o.dataId); if (l.complexTensorInfos != null) { const u = l.complexTensorInfos.real, d = l.complexTensorInfos.imag; u.shape = a, d.shape = a } return { dataId: o.dataId, shape: a, dtype: o.dtype } } const bL = { kernelName: nc, backendName: "cpu", kernelFunc: zt };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gy(n) { const { inputs: t, backend: e, attrs: s } = n, { a: o, b: r } = t, { transposeA: i, transposeB: a } = s; it([o, r], "matMul"); const c = o.shape.length, l = r.shape.length, u = i ? o.shape[c - 2] : o.shape[c - 1], d = a ? r.shape[l - 1] : r.shape[l - 2], h = i ? o.shape[c - 1] : o.shape[c - 2], p = a ? r.shape[l - 2] : r.shape[l - 1], f = o.shape.slice(0, -2), m = r.shape.slice(0, -2), g = Z(f), b = Z(m), I = gt(o.shape.slice(0, -2), r.shape.slice(0, -2)).concat([h, p]); v(u === d, () => `Error in matMul: inner shapes (${u}) and (${d}) of Tensors with shapes ${o.shape} and ${r.shape} and transposeA=${i} and transposeB=${a} must match.`); const y = i ? [g, u, h] : [g, h, u], C = a ? [b, p, d] : [b, d, p], w = zt({ inputs: { x: o }, backend: e, attrs: { shape: y } }), k = zt({ inputs: { x: r }, backend: e, attrs: { shape: C } }), S = i ? w.shape[1] : w.shape[2], T = i ? w.shape[2] : w.shape[1], R = a ? k.shape[1] : k.shape[2], G = Math.max(g, b), F = e.data.get(w.dataId).values, V = e.data.get(k.dataId).values, z = ct(w.shape), X = ct(k.shape), [O, B, K] = i ? [z[0], 1, z[1]] : [z[0], z[1], 1], [H, U, Y] = a ? [1, X[1], X[0]] : [X[1], 1, X[0]], j = T * R, J = Ct([G, T, R], w.dtype), nt = J.values, q = e.blockSize; for (let rt = 0; rt < G; rt++) { const lt = rt % g, pt = rt % b; for (let ht = 0; ht < T; ht += q) { const xt = Math.min(ht + q, T); for (let yt = 0; yt < R; yt += q) { const Et = Math.min(yt + q, R); for (let At = 0; At < S; At += q) { const jt = Math.min(At + q, S); for (let Ot = ht; Ot < xt; Ot++)for (let Dt = yt; Dt < Et; Dt++) { let Jt = 0; for (let Ut = At; Ut < jt; Ut++) { const ls = F[lt * O + Ot * B + Ut * K], ve = V[Ut * H + Dt * U + pt * Y]; Jt += ls * ve } nt[rt * j + (Ot * R + Dt)] += Jt } } } } } return e.disposeIntermediateTensorInfo(w), e.disposeIntermediateTensorInfo(k), e.makeTensorInfo(I, J.dtype, J.values) } const xL = { kernelName: Ia, backendName: "cpu", kernelFunc: Gy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yL(n) { const { inputs: t, backend: e, attrs: s } = n, { a: o, b: r, bias: i, preluActivationWeights: a } = t, { transposeA: c, transposeB: l, activation: u, leakyreluAlpha: d } = s; let h, p, f; const m = []; h = Gy({ inputs: { a: o, b: r }, attrs: { transposeA: c, transposeB: l }, backend: e }), i && (p = qo({ inputs: { a: h, b: i }, backend: e }), m.push(h), h = p), u && (f = hl(e, h, u, a, d), m.push(h), h = f); for (const b of m) e.disposeIntermediateTensorInfo(b); return h } const IL = { kernelName: mc, backendName: "cpu", kernelFunc: yL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const CL = Lt(yr, n => Math.acos(n)), wL = { kernelName: yr, backendName: "cpu", kernelFunc: CL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const vL = Lt(Ir, n => Math.acosh(n)), SL = { kernelName: Ir, backendName: "cpu", kernelFunc: vL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kL(n) { const { inputs: t, backend: e } = n, s = t; it(t, "addN"); const o = s.map(a => e.data.get(a.dataId).values), r = Ct(s[0].shape, s[0].dtype), i = r.values; for (let a = 0; a < s.length; a++) { const c = o[a]; for (let l = 0; l < i.length; l++)i[l] += c[l] } return e.makeTensorInfo(r.shape, r.dtype, r.values) } const TL = { kernelName: jl, backendName: "cpu", kernelFunc: kL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function NL(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; it(o, "all"); const a = It(r, o.shape); let c = a; const l = Yt(c, o.shape.length); let u = o; l != null && (u = Ae({ inputs: { x: o }, backend: e, attrs: { perm: l } }), c = te(c.length, o.shape.length)), Ie("all", c, u.shape.length); const [d, h] = fe(u.shape, c), p = Z(h), f = Se(Z(d), u.dtype), m = e.data.get(u.dataId).values; for (let b = 0; b < f.length; ++b) { const x = b * p; let I = m[x]; for (let y = 0; y < p; ++y) { const C = m[x + y]; I = I && C } f[b] = I } l != null && e.disposeIntermediateTensorInfo(u); const g = e.makeTensorInfo(d, u.dtype, f); if (i) { const b = oe(d, a), x = zt({ inputs: { x: g }, backend: e, attrs: { shape: b } }); return e.disposeIntermediateTensorInfo(g), x } return g } const RL = { kernelName: ql, backendName: "cpu", kernelFunc: NL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $L(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; it(o, "any"); const a = It(r, o.shape); let c = a; const l = Yt(c, o.shape.length); let u = o; l != null && (u = Ae({ inputs: { x: o }, backend: e, attrs: { perm: l } }), c = te(c.length, o.shape.length)), Ie("any", c, u.shape.length); const [d, h] = fe(u.shape, c), p = Z(h), f = Se(Z(d), u.dtype), m = e.data.get(u.dataId).values; for (let b = 0; b < f.length; ++b) { const x = b * p; let I = m[x]; for (let y = 0; y < p; ++y) { const C = m[x + y]; I = I || C } f[b] = I } l != null && e.disposeIntermediateTensorInfo(u); const g = e.makeTensorInfo(d, u.dtype, f); if (i) { const b = oe(d, a), x = zt({ inputs: { x: g }, backend: e, attrs: { shape: b } }); return e.disposeIntermediateTensorInfo(g), x } return g } const GL = { kernelName: tu, backendName: "cpu", kernelFunc: $L };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function LL(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r } = s; it(o, "argMax"); let i = It(r, o.shape); const a = Yt(i, o.shape.length); let c = o; const l = []; a != null && (c = Ae({ inputs: { x: o }, backend: e, attrs: { perm: a } }), l.push(c), i = te(i.length, c.shape.length)), i = [i[0]], Ie("argMax", i, c.shape.length); const [u, d] = fe(c.shape, i), h = Z(u), p = Se(h, "int32"), f = Z(d), m = e.data.get(c.dataId).values; for (let g = 0; g < p.length; ++g) { const b = g * f; let x = m[b], I = 0; for (let y = 0; y < f; ++y) { const C = m[b + y]; C > x && (x = C, I = y) } p[g] = I } return l.forEach(g => e.disposeIntermediateTensorInfo(g)), e.makeTensorInfo(u, "int32", p) } const EL = { kernelName: ga, backendName: "cpu", kernelFunc: LL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function DL(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r } = s; it(o, "argMin"); let i = It(r, o.shape); const a = Yt(i, o.shape.length); let c = o; const l = []; a != null && (c = Ae({ inputs: { x: o }, backend: e, attrs: { perm: a } }), l.push(c), i = te(i.length, c.shape.length)), i = [i[0]], Ie("argMin", i, c.shape.length); const [u, d] = fe(c.shape, i), h = Z(u), p = Se(h, "int32"), f = Z(d), m = e.data.get(c.dataId).values; for (let g = 0; g < p.length; ++g) { const b = g * f; let x = m[b], I = 0; for (let y = 0; y < f; ++y) { const C = m[b + y]; C < x && (x = C, I = y) } p[g] = I } return l.forEach(g => e.disposeIntermediateTensorInfo(g)), e.makeTensorInfo(u, "int32", p) } const WL = { kernelName: ba, backendName: "cpu", kernelFunc: DL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ML = Lt(Cr, n => Math.asin(n)), FL = { kernelName: Cr, backendName: "cpu", kernelFunc: ML };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const VL = Lt(wr, n => Math.asinh(n)), zL = { kernelName: wr, backendName: "cpu", kernelFunc: VL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const XL = Lt(vr, n => Math.atan(n)), AL = { kernelName: vr, backendName: "cpu", kernelFunc: XL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const OL = ae((n, t) => Math.atan2(n, t)), PL = be(kr, OL), KL = { kernelName: kr, backendName: "cpu", kernelFunc: PL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ZL = Lt(Sr, n => Math.atanh(n)), BL = { kernelName: Sr, backendName: "cpu", kernelFunc: ZL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lp(n, t, e, s, o, r) { const i = o.strideHeight, a = o.strideWidth, c = o.dilationHeight, l = o.dilationWidth, u = o.effectiveFilterHeight, d = o.effectiveFilterWidth, h = o.padInfo.top, p = o.padInfo.left, f = r === "max" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, m = Ct(o.outShape, e), g = m.values, b = o.outShape[1] * o.outShape[2] * o.outShape[3], x = o.outShape[2] * o.outShape[3], I = o.outShape[3]; for (let y = 0; y < o.batchSize; ++y) { const C = y * b, w = y * s[0]; for (let k = 0; k < o.inChannels; ++k)for (let S = 0; S < o.outHeight; ++S) { const T = S * i - h, R = Math.max(0, T), G = Math.min(o.inHeight, u + T), F = C + S * x; for (let V = 0; V < o.outWidth; ++V) { const z = V * a - p, X = Math.max(0, z), O = Math.min(o.inWidth, d + z); let B = f, K = 0, H = 0; for (let Y = R; Y < G; Y += c) { const j = w + Y * s[1]; for (let J = X; J < O; J += l) { const nt = j + J * s[2], q = n[nt + k]; r === "max" && q > B ? B = q : r === "avg" && (K += q, H++) } if (isNaN(B)) break } const U = F + V * I + k; g[U] = r === "avg" ? K / H : B } } } return m } function Ly(n, t, e, s, o = !1, r = !1) { const i = Ct(s.outShape, "int32"), a = s.strideHeight, c = s.strideWidth, l = s.dilationHeight, u = s.dilationWidth, d = s.effectiveFilterHeight, h = s.effectiveFilterWidth, p = s.padInfo.top, f = s.padInfo.left, m = Ct(t, e, n); for (let g = 0; g < s.batchSize; ++g)for (let b = 0; b < s.inChannels; ++b)for (let x = 0; x < s.outHeight; ++x) { const I = x * a - p; let y = I; for (; y < 0;)y += l; const C = Math.min(s.inHeight, d + I); for (let w = 0; w < s.outWidth; ++w) { const k = w * c - f; let S = k; for (; S < 0;)S += u; const T = Math.min(s.inWidth, h + k); let R = Number.NEGATIVE_INFINITY, G = -1; for (let F = y; F < C; F += l) { const V = F - I; for (let z = S; z < T; z += u) { const X = z - k, O = m.get(g, F, z, b); O > R && (R = O, o ? G = r ? ((g * s.inHeight + F) * s.inWidth + z) * s.inChannels + b : (F * s.inWidth + z) * s.inChannels + b : G = V * h + X) } } i.set(G, g, x, w, b) } } return i } function Ey(n, t, e, s, o, r) { const i = o.strideDepth, a = o.strideHeight, c = o.strideWidth, l = o.dilationDepth, u = o.dilationHeight, d = o.dilationWidth, h = o.effectiveFilterDepth, p = o.effectiveFilterHeight, f = o.effectiveFilterWidth, m = o.padInfo.front, g = o.padInfo.top, b = o.padInfo.left, x = r === "max" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, I = Ct(o.outShape, e), y = I.values, C = o.outShape[1] * o.outShape[2] * o.outShape[3] * o.outShape[4], w = o.outShape[2] * o.outShape[3] * o.outShape[4], k = o.outShape[3] * o.outShape[4], S = o.outShape[4]; for (let T = 0; T < o.batchSize; ++T) { const R = T * C, G = T * s[0]; for (let F = 0; F < o.inChannels; ++F)for (let V = 0; V < o.outDepth; ++V) { const z = V * i - m; let X = z; for (; X < 0;)X += l; const O = Math.min(o.inDepth, h + z), B = R + V * w; for (let K = 0; K < o.outHeight; ++K) { const H = K * a - g; let U = H; for (; U < 0;)U += u; const Y = Math.min(o.inHeight, p + H), j = B + K * k; for (let J = 0; J < o.outWidth; ++J) { const nt = J * c - b; let q = nt; for (; q < 0;)q += d; const rt = Math.min(o.inWidth, f + nt), lt = j + J * S; let pt = x, ht = 0, xt = 0; for (let Et = X; Et < O; Et += l) { const At = G + Et * s[1]; for (let jt = U; jt < Y; jt += u) { const Ot = At + jt * s[2]; for (let Dt = q; Dt < rt; Dt += d) { const Jt = Ot + Dt * s[3], Ut = n[Jt + F]; if (r === "max" && Ut > pt ? pt = Ut : r === "avg" && (ht += Ut, xt++), isNaN(pt)) break } if (isNaN(pt)) break } if (isNaN(pt)) break } const yt = lt + F; y[yt] = r === "avg" ? ht / Math.max(xt, 1) : pt } } } } return I } function HL(n, t) { const e = Ct(t.outShape, "int32"), s = t.strideDepth, o = t.strideHeight, r = t.strideWidth, i = t.dilationDepth, a = t.dilationHeight, c = t.dilationWidth, l = t.effectiveFilterDepth, u = t.effectiveFilterHeight, d = t.effectiveFilterWidth, h = t.padInfo.front, p = t.padInfo.top, f = t.padInfo.left; for (let m = 0; m < t.batchSize; ++m)for (let g = 0; g < t.inChannels; ++g)for (let b = 0; b < t.outDepth; ++b) { const x = b * s - h; let I = x; for (; I < 0;)I += i; const y = Math.min(t.inDepth, l + x); for (let C = 0; C < t.outHeight; ++C) { const w = C * o - p; let k = w; for (; k < 0;)k += a; const S = Math.min(t.inHeight, u + w); for (let T = 0; T < t.outWidth; ++T) { const R = T * r - f; let G = R; for (; G < 0;)G += c; const F = Math.min(t.inWidth, d + R); let V = Number.NEGATIVE_INFINITY, z = -1; for (let X = I; X < y; X += i) { const O = X - x; for (let B = k; B < S; B += a) { const K = B - w; for (let H = G; H < F; H += c) { const U = H - R, Y = n.get(m, X, B, H, g); Y >= V && (V = Y, z = O * u * d + K * u + U) } } } e.set(z, m, b, C, T, g) } } } return e }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _L(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t; it(o, "avgPool"); const { filterSize: r, strides: i, pad: a, dimRoundingMode: c } = s, l = 1; v(Te(i, l), () => `Error in avgPool: Either strides or dilations must be 1. Got strides ${i} and dilations '${l}'`); const u = hn(o.shape, r, i, l, a, c); let d; if (u.filterWidth === 1 && u.filterHeight === 1 && Rt(u.inShape, u.outShape)) d = Un({ inputs: { x: o }, backend: e }); else { const h = e.data.get(o.dataId).values, p = ct(o.shape), f = lp(h, o.shape, o.dtype, p, u, "avg"); d = e.makeTensorInfo(u.outShape, o.dtype, f.values) } return d } const UL = { kernelName: xa, backendName: "cpu", kernelFunc: _L };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function YL(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { filterSize: r, strides: i, pad: a, dimRoundingMode: c, dataFormat: l } = s; it(o, "avgPool3d"); const u = ts(o.shape, r, i, 1, a, c, l), d = e.data.get(o.dataId).values, h = Ey(d, o.shape, o.dtype, ct(o.shape), u, "avg"); return e.makeTensorInfo(h.shape, "float32", h.values) } const QL = { kernelName: ya, backendName: "cpu", kernelFunc: YL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JL(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, { filterSize: i, strides: a, pad: c, dimRoundingMode: l } = s; it([o, r], "avgPool3DGrad"); const u = ts(r.shape, i, a, 1, c, l), d = u.strideDepth, h = u.strideHeight, p = u.strideWidth, f = u.filterDepth, m = u.filterHeight, g = u.filterWidth, b = u.dilationDepth, x = u.dilationHeight, I = u.dilationWidth, y = u.effectiveFilterDepth, C = u.effectiveFilterHeight, w = u.effectiveFilterWidth, k = y - 1 - u.padInfo.front, S = w - 1 - u.padInfo.left, T = C - 1 - u.padInfo.top, R = Ct(r.shape, "float32"), G = 1 / (f * m * g), F = e.bufferSync(o); for (let V = 0; V < u.batchSize; ++V)for (let z = 0; z < u.inChannels; ++z)for (let X = 0; X < u.inDepth; ++X)for (let O = 0; O < u.inHeight; ++O)for (let B = 0; B < u.inWidth; ++B) { const K = X - k, H = O - T, U = B - S; let Y = 0; for (let j = 0; j < y; j += b) { const J = (K + j) / d; if (!(J < 0 || J >= u.outDepth || Math.floor(J) !== J)) for (let nt = 0; nt < C; nt += x) { const q = (H + nt) / h; if (!(q < 0 || q >= u.outHeight || Math.floor(q) !== q)) for (let rt = 0; rt < w; rt += I) { const lt = (U + rt) / p; if (lt < 0 || lt >= u.outWidth || Math.floor(lt) !== lt) continue; const pt = F.get(V, J, q, lt, z); Y += pt } } } R.set(Y * G, V, X, O, B, z) } return e.makeTensorInfo(R.shape, R.dtype, R.values) } const jL = { kernelName: nu, backendName: "cpu", kernelFunc: JL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qL(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, i = r; it([o, r], "avgPoolGrad"); const { filterSize: a, strides: c, pad: l } = s, u = hn(i.shape, a, c, 1, l), d = u.strideHeight, h = u.strideWidth, p = u.filterHeight, f = u.filterWidth, m = u.dilationHeight, g = u.dilationWidth, b = u.effectiveFilterHeight, x = u.effectiveFilterWidth, I = x - 1 - u.padInfo.left, y = b - 1 - u.padInfo.top, C = Ct(i.shape, "float32"), w = 1 / (p * f), k = e.data.get(o.dataId).values, S = Ct(o.shape, "float32", k); for (let T = 0; T < u.batchSize; ++T)for (let R = 0; R < u.inChannels; ++R)for (let G = 0; G < u.inHeight; ++G)for (let F = 0; F < u.inWidth; ++F) { const V = G - y, z = F - I; let X = 0; for (let O = 0; O < b; O += m) { const B = (V + O) / d; if (!(B < 0 || B >= u.outHeight || Math.floor(B) !== B)) for (let K = 0; K < x; K += g) { const H = (z + K) / h; if (H < 0 || H >= u.outWidth || Math.floor(H) !== H) continue; const U = S.get(T, B, H, R); X += U } } C.set(X * w, T, G, F, R) } return e.makeTensorInfo(C.shape, C.dtype, C.values) } const tE = { kernelName: eu, backendName: "cpu", kernelFunc: qL };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function eE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, scale: r, offset: i, mean: a, variance: c } = t; v(a.shape.length === c.shape.length, () => "Batch normalization gradient requires mean and variance to have equal ranks."), v(i == null || a.shape.length === i.shape.length, () => "Batch normalization gradient requires mean and offset to have equal ranks."), v(r == null || a.shape.length === r.shape.length, () => "Batch normalization gradient requires mean and scale to have equal ranks."), it([o, a, c, r, i], "batchNorm"); let { varianceEpsilon: l } = s; l == null && (l = .001); const u = e.data.get(o.dataId).values, d = e.data.get(a.dataId).values, h = e.data.get(c.dataId).values, p = r ? e.data.get(r.dataId).values : new Float32Array([1]), f = i ? e.data.get(i.dataId).values : new Float32Array([0]), m = new Float32Array(u.length), g = f.length, b = p.length, x = h.length, I = d.length; let y = 0, C = 0, w = 0, k = 0; for (let S = 0; S < u.length; ++S)m[S] = f[y++] + (u[S] - d[C++]) * p[w++] / Math.sqrt(h[k++] + l), y >= g && (y = 0), C >= I && (C = 0), w >= b && (w = 0), k >= x && (k = 0); return e.makeTensorInfo(o.shape, o.dtype, m) } const nE = { kernelName: Ea, backendName: "cpu", kernelFunc: eE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockShape: r, crops: i } = s; it([o], "batchToSpaceND"); const a = r.reduce((b, x) => b * x), c = $i(o.shape, r, a), l = Gi(c.length, r.length), u = Li(o.shape, r, a), d = eh(i, r.length), h = nh(u, i, r.length), p = zt({ inputs: { x: o }, backend: e, attrs: { shape: c } }), f = Ae({ inputs: { x: p }, backend: e, attrs: { perm: l } }), m = zt({ inputs: { x: f }, backend: e, attrs: { shape: u } }), g = xo({ inputs: { x: m }, backend: e, attrs: { begin: d, size: h } }); return e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), e.disposeIntermediateTensorInfo(m), g } const oE = { kernelName: Ca, backendName: "cpu", kernelFunc: sE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, weights: r } = t, { size: i } = s, a = e.data.get(o.dataId).values, c = e.data.get(r.dataId).values, l = op(a, c, r.dtype, r.shape, i); return e.makeTensorInfo([i], r.dtype, l) } const iE = { kernelName: su, backendName: "cpu", kernelFunc: rE };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aE(n) { const { inputs: t, backend: e } = n, { s0: s, s1: o } = t, r = e.data.get(s.dataId).values, i = e.data.get(o.dataId).values, a = gt(Array.from(r), Array.from(i)); return e.makeTensorInfo([a.length], "int32", Int32Array.from(a)) } const cE = { kernelName: df, backendName: "cpu", kernelFunc: aE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const lE = Lt(Rr, (n, t) => { const e = t; return n > e.clipValueMax ? e.clipValueMax : n < e.clipValueMin ? e.clipValueMin : n }), uE = { kernelName: Rr, backendName: "cpu", kernelFunc: lE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const dE = { kernelName: wa, backendName: "cpu", kernelFunc: n => { const { x: t } = n.inputs, e = n.backend, s = new Float32Array(Z(t.shape)), o = e.data.get(t.dataId), r = o.complexTensorInfos.real, i = o.complexTensorInfos.imag, a = e.data.get(r.dataId).values, c = e.data.get(i.dataId).values; for (let l = 0; l < a.length; l++) { const u = a[l], d = c[l]; s[l] = Math.hypot(u, d) } return e.makeOutput(s, t.shape, "float32") } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nr(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = e.data.get(s.dataId).complexTensorInfos.imag, r = e.data.get(o.dataId).values; return e.makeTensorInfo(o.shape, o.dtype, r) } const hE = { kernelName: Cu, backendName: "cpu", kernelFunc: nr };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sr(n) { const { inputs: t, backend: e, attrs: s } = n, { axis: o } = s, r = It(o, t[0].shape)[0], i = t.map(m => m.shape); jd(i, r); let a = On(t.map(m => m.shape), r); if (Z(a) === 0) return e.makeTensorInfo(a, t[0].dtype, []); const c = t.filter(m => Z(m.shape) > 0); if (c.length === 1) return Un({ inputs: { x: c[0] }, backend: e }); if (c[0].dtype === "complex64") { const m = c.map(y => bo({ inputs: { input: y }, backend: e })), g = c.map(y => nr({ inputs: { input: y }, backend: e })), b = sr({ inputs: m, backend: e, attrs: { axis: r } }), x = sr({ inputs: g, backend: e, attrs: { axis: r } }), I = Ue({ inputs: { real: b, imag: x }, backend: e }); return m.forEach(y => e.disposeIntermediateTensorInfo(y)), g.forEach(y => e.disposeIntermediateTensorInfo(y)), e.disposeIntermediateTensorInfo(b), e.disposeIntermediateTensorInfo(x), I } const l = c.map(m => { const b = [-1, Z(m.shape.slice(r))]; return zt({ inputs: { x: m }, backend: e, attrs: { shape: b } }) }), u = l.map(m => ({ vals: e.data.get(m.dataId).values, shape: m.shape })); a = On(l.map(m => m.shape), 1); const d = l[0].shape[0] === 1, h = Mx(u, a, t[0].dtype, d), p = On(c.map(m => m.shape), r), f = e.makeTensorInfo(p, t[0].dtype, h); return l.forEach(m => e.disposeIntermediateTensorInfo(m)), f } const pE = { kernelName: va, backendName: "cpu", kernelFunc: sr };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Dy(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dataFormat: c, dilations: l, dimRoundingMode: u } = s; it([o, r], "conv2d"); const d = es(c), h = ye(o.shape, r.shape, i, l, a, u, !1, d), p = h.filterHeight, f = h.filterWidth, m = h.dilationHeight, g = h.dilationWidth, b = h.padInfo.left, x = h.padInfo.top, I = h.dataFormat === "channelsLast", y = new ke(h.outShape, o.dtype), C = ct(o.shape), w = ct(r.shape), k = C[0], S = I ? C[1] : C[2], T = I ? C[2] : 1, R = I ? 1 : C[1], G = y.strides[0], F = I ? y.strides[1] : y.strides[2], V = I ? y.strides[2] : 1, z = I ? 1 : y.strides[1], X = e.data.get(o.dataId).values, O = e.data.get(r.dataId).values, B = y.values; for (let K = 0; K < h.batchSize; ++K) { const H = K * k, U = K * G; for (let Y = 0; Y < h.outHeight; ++Y) { const j = U + Y * F, J = Y * h.strideHeight - x; for (let nt = 0; nt < p; ++nt) { const q = J + nt * m; if (q < 0 || q >= h.inHeight) continue; const rt = nt * w[0], lt = H + q * S; for (let pt = 0; pt < h.outWidth; ++pt) { const ht = j + pt * V, xt = pt * h.strideWidth - b; for (let yt = 0; yt < f; ++yt) { const Et = xt + yt * g; if (Et < 0 || Et >= h.inWidth) continue; const At = rt + yt * w[1], jt = lt + Et * T; let Ot = At; for (let Dt = 0; Dt < h.inChannels; ++Dt) { const Jt = X[jt + Dt * R]; for (let Ut = 0; Ut < h.outChannels; ++Ut)B[ht + Ut * z] += Jt * O[Ot + Ut]; Ot += h.outChannels } } } } } } return e.makeTensorInfo(y.shape, y.dtype, B) } const fE = { kernelName: Sa, backendName: "cpu", kernelFunc: Dy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, pad: a, dataFormat: c, dimRoundingMode: l, filterShape: u } = s; it([o, r], "conv2dBackpropFilter"); const d = es(c), h = ye(o.shape, u, i, 1, a, l, !1, d), { strideHeight: p, strideWidth: f, filterHeight: m, filterWidth: g } = h, b = h.dataFormat === "channelsLast", x = new ke(h.filterShape, "float32"), I = h.padInfo.left, y = h.padInfo.top, C = e.data.get(o.dataId).values, w = e.data.get(r.dataId).values, k = new ke(o.shape, o.dtype, C), S = new ke(r.shape, r.dtype, w); for (let T = 0; T < m; ++T) { const R = Math.max(0, Math.ceil((y - T) / p)), G = Math.min(h.outHeight, (h.inHeight + y - T) / p); for (let F = 0; F < g; ++F) { const V = Math.max(0, Math.ceil((I - F) / f)), z = Math.min(h.outWidth, (h.inWidth + I - F) / f); for (let X = 0; X < h.inChannels; ++X)for (let O = 0; O < h.outChannels; ++O) { let B = 0; for (let K = 0; K < h.batchSize; ++K)for (let H = R; H < G; ++H) { const U = T + H * p - y; for (let Y = V; Y < z; ++Y) { const j = F + Y * f - I; b ? B += k.get(K, U, j, X) * S.get(K, H, Y, O) : B += k.get(K, X, U, j) * S.get(K, O, H, Y) } } x.set(B, T, F, X, O) } } } return e.makeTensorInfo(x.shape, x.dtype, x.values) } const gE = { kernelName: ru, backendName: "cpu", kernelFunc: mE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bE(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { inputShape: i, strides: a, pad: c, dataFormat: l, dimRoundingMode: u } = s; it([o, r], "conv2dBackpropInput"); const d = ct(r.shape), h = ct(o.shape); let p = es(l); const f = ye(i, r.shape, a, 1, c, u, !1, p), m = new ke(f.inShape, "float32"), g = m.values, b = e.data.get(o.dataId).values, x = e.data.get(r.dataId).values, [I, y, C] = d, { batchSize: w, filterHeight: k, filterWidth: S, inChannels: T, inHeight: R, inWidth: G, outChannels: F, outHeight: V, outWidth: z, strideHeight: X, strideWidth: O } = f; p = f.dataFormat; const B = k - 1 - f.padInfo.top, K = S - 1 - f.padInfo.left, H = p === "channelsLast", U = m.strides[0], Y = H ? m.strides[1] : m.strides[2], j = H ? m.strides[2] : 1, J = H ? 1 : m.strides[1], nt = h[0], q = H ? h[1] : h[2], rt = H ? h[2] : 1, lt = H ? 1 : h[1]; for (let pt = 0; pt < w; ++pt)for (let ht = 0; ht < T; ++ht)for (let xt = 0; xt < R; ++xt) { const yt = xt - B, Et = Math.max(0, Math.ceil(yt / X)), At = Math.min(V, (k + yt) / X); for (let jt = 0; jt < G; ++jt) { const Ot = jt - K, Dt = Math.max(0, Math.ceil(Ot / O)), Jt = Math.min(z, (S + Ot) / O); let Ut = 0; for (let ve = Et; ve < At; ++ve) { const Ms = ve * X - yt; for (let cn = Dt; cn < Jt; ++cn) { const To = cn * O - Ot, Fn = nt * pt + q * ve + rt * cn, us = I * (k - 1 - Ms) + y * (S - 1 - To) + C * ht; for (let Fs = 0; Fs < F; ++Fs) { const Vs = b[Fn + lt * Fs], zs = x[us + Fs]; Ut += Vs * zs } } } const ls = U * pt + Y * xt + j * jt + J * ht; g[ls] = Ut } } return e.makeTensorInfo(m.shape, m.dtype, m.values) } const xE = { kernelName: ka, backendName: "cpu", kernelFunc: bE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dilations: c } = s; it([o, r], "conv3d"); const l = xs(o.shape, r.shape, i, c, a), { filterDepth: u, filterHeight: d, filterWidth: h, dilationDepth: p, dilationHeight: f, dilationWidth: m, padInfo: g } = l, b = g.front, x = g.left, I = g.top, y = new ke(l.outShape, o.dtype), C = e.data.get(o.dataId).values, w = e.data.get(r.dataId).values, k = y.values, S = ct(o.shape), T = ct(r.shape); for (let R = 0; R < l.batchSize; ++R) { const G = R * S[0], F = R * y.strides[0]; for (let V = 0; V < l.outDepth; ++V) { const z = F + V * y.strides[1], X = V * l.strideDepth - b; for (let O = 0; O < u; ++O) { const B = X + O * p; if (B < 0 || B >= l.inDepth) continue; const K = O * T[0], H = G + B * S[1]; for (let U = 0; U < l.outHeight; ++U) { const Y = z + U * y.strides[2], j = U * l.strideHeight - I; for (let J = 0; J < d; ++J) { const nt = j + J * f; if (nt < 0 || nt >= l.inHeight) continue; const q = K + J * T[1], rt = H + nt * S[2]; for (let lt = 0; lt < l.outWidth; ++lt) { const pt = Y + lt * l.outChannels, ht = lt * l.strideWidth - x; for (let xt = 0; xt < h; ++xt) { const yt = ht + xt * m; if (yt < 0 || yt >= l.inWidth) continue; const Et = q + xt * T[2], At = rt + yt * l.inChannels; let jt = Et; for (let Ot = 0; Ot < l.inChannels; ++Ot) { const Dt = C[At + Ot]; for (let Jt = 0; Jt < l.outChannels; ++Jt)k[pt + Jt] += Dt * w[jt + Jt]; jt += l.outChannels } } } } } } } } return e.makeTensorInfo(y.shape, y.dtype, y.values) } const IE = { kernelName: Ta, backendName: "cpu", kernelFunc: yE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function CE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, pad: a, filterShape: c } = s; it([o, r], "conv3dBackpropFilterV2"); const l = ct(o.shape), u = ct(r.shape), d = xs(o.shape, c, i, 1, a), h = d.strideDepth, p = d.strideHeight, f = d.strideWidth, m = d.filterDepth, g = d.filterHeight, b = d.filterWidth, x = new ke(d.filterShape, "float32"), I = x.values, [y, C, w, k] = x.strides, S = e.data.get(r.dataId).values, [T, R, G, F] = u, V = e.data.get(o.dataId).values, [z, X, O, B] = l, K = d.padInfo.front, H = d.padInfo.left, U = d.padInfo.top; for (let Y = 0; Y < m; ++Y) { const j = Math.max(0, Math.ceil((K - Y) / h)), J = Math.min(d.outDepth, (d.inDepth + K - Y) / h), nt = Y * y; for (let q = 0; q < g; ++q) { const rt = Math.max(0, Math.ceil((U - q) / p)), lt = Math.min(d.outHeight, (d.inHeight + U - q) / p), pt = q * C + nt; for (let ht = 0; ht < b; ++ht) { const xt = Math.max(0, Math.ceil((H - ht) / f)), yt = Math.min(d.outWidth, (d.inWidth + H - ht) / f), Et = ht * w + pt; for (let At = 0; At < d.inChannels; ++At) { const jt = At * k + Et; for (let Ot = 0; Ot < d.outChannels; ++Ot) { let Dt = 0; for (let Jt = 0; Jt < d.batchSize; ++Jt) { const Ut = Jt * z, ls = Jt * T; for (let ve = j; ve < J; ++ve) { const cn = (Y + ve * h - K) * X + Ut, To = ve * R + ls; for (let Fn = rt; Fn < lt; ++Fn) { const Fs = (q + Fn * p - U) * O + cn, Vs = Fn * G + To; for (let zs = xt; zs < yt; ++zs) { const qp = (ht + zs * f - H) * B + Fs, tf = zs * F + Vs; Dt += V[qp + At] * S[tf + Ot] } } } } I[jt + Ot] = Dt } } } } } return e.makeTensorInfo(x.shape, x.dtype, x.values) } const wE = { kernelName: iu, backendName: "cpu", kernelFunc: CE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function vE(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { pad: i, strides: a, inputShape: c } = s; it([o], "conv3dBackpropInputV2"); const l = ct(o.shape), u = ct(r.shape), d = xs(c, r.shape, a, 1, i), h = new ke(d.inShape, "float32"), p = h.values, [f, m, g, b] = h.strides, x = e.data.get(o.dataId).values, [I, y, C, w] = l, k = e.data.get(r.dataId).values, [S, T, R, G] = u, { batchSize: F, filterDepth: V, filterHeight: z, filterWidth: X, inChannels: O, inDepth: B, inHeight: K, inWidth: H, outChannels: U, outDepth: Y, outHeight: j, outWidth: J, strideDepth: nt, strideHeight: q, strideWidth: rt } = d, lt = V - 1 - d.padInfo.front, pt = z - 1 - d.padInfo.top, ht = X - 1 - d.padInfo.left; for (let xt = 0; xt < F; ++xt)for (let yt = 0; yt < O; ++yt)for (let Et = 0; Et < B; ++Et) { const At = Et - lt, jt = Math.max(0, Math.ceil(At / nt)), Ot = Math.min(Y, (V + At) / nt); for (let Dt = 0; Dt < K; ++Dt) { const Jt = Dt - pt, Ut = Math.max(0, Math.ceil(Jt / q)), ls = Math.min(j, (z + Jt) / q); for (let ve = 0; ve < H; ++ve) { const Ms = ve - ht, cn = Math.max(0, Math.ceil(Ms / rt)), To = Math.min(J, (X + Ms) / rt); let Fn = 0; for (let us = jt; us < Ot; ++us) { const Fs = us * nt - At; for (let Vs = Ut; Vs < ls; ++Vs) { const zs = Vs * q - Jt; for (let pa = cn; pa < To; ++pa) { const qp = pa * rt - Ms, tf = I * xt + y * us + C * Vs + w * pa, j9 = S * (V - 1 - Fs) + T * (z - 1 - zs) + R * (X - 1 - qp) + G * yt; for (let Xl = 0; Xl < U; ++Xl) { const q9 = x[tf + Xl], t_ = k[j9 + Xl]; Fn += q9 * t_ } } } } p[f * xt + m * Et + g * Dt + b * ve + yt] = Fn } } } return e.makeTensorInfo(h.shape, h.dtype, h.values) } const SE = { kernelName: au, backendName: "cpu", kernelFunc: vE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kE = Lt($r, n => Math.cos(n)), TE = { kernelName: $r, backendName: "cpu", kernelFunc: kE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const NE = Lt(Gr, n => Math.cosh(n)), RE = { kernelName: Gr, backendName: "cpu", kernelFunc: NE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $E(n) { const { inputs: t, backend: e, attrs: s } = n, { image: o, boxes: r, boxInd: i } = t, { cropSize: a, method: c, extrapolationValue: l } = s, [u, d, h, p] = o.shape, f = r.shape[0], [m, g] = a, b = Ct([f, m, g, p], "float32"), x = e.data.get(r.dataId).values, I = e.data.get(i.dataId).values, y = e.data.get(o.dataId).values, C = ct(o.shape), w = ct(b.shape); for (let k = 0; k < f; k++) { const S = k * 4, T = x[S], R = x[S + 1], G = x[S + 2], F = x[S + 3], V = I[k]; if (V >= u) continue; const z = m > 1 ? (G - T) * (d - 1) / (m - 1) : 0, X = g > 1 ? (F - R) * (h - 1) / (g - 1) : 0; for (let O = 0; O < m; O++) { const B = m > 1 ? T * (d - 1) + O * z : .5 * (T + G) * (d - 1); if (B < 0 || B > d - 1) { for (let K = 0; K < g; K++)for (let H = 0; H < p; H++) { const U = H + K * w[2] + O * w[1] + k * w[0]; b.values[U] = l } continue } if (c === "bilinear") { const K = Math.floor(B), H = Math.ceil(B), U = B - K; for (let Y = 0; Y < g; Y++) { const j = g > 1 ? R * (h - 1) + Y * X : .5 * (R + F) * (h - 1); if (j < 0 || j > h - 1) { for (let rt = 0; rt < p; rt++) { const lt = rt + Y * w[2] + O * w[1] + k * w[0]; b.values[lt] = l } continue } const J = Math.floor(j), nt = Math.ceil(j), q = j - J; for (let rt = 0; rt < p; rt++) { let lt = rt + J * C[2] + K * C[1] + V * C[0]; const pt = y[lt]; lt = rt + nt * C[2] + K * C[1] + V * C[0]; const ht = y[lt]; lt = rt + J * C[2] + H * C[1] + V * C[0]; const xt = y[lt]; lt = rt + nt * C[2] + H * C[1] + V * C[0]; const yt = y[lt], Et = pt + (ht - pt) * q, At = xt + (yt - xt) * q; lt = rt + Y * w[2] + O * w[1] + k * w[0], b.values[lt] = Et + (At - Et) * U } } } else for (let K = 0; K < g; ++K) { const H = g > 1 ? R * (h - 1) + K * X : .5 * (R + F) * (h - 1); if (H < 0 || H > h - 1) { for (let j = 0; j < p; j++) { const J = j + K * w[2] + O * w[1] + k * w[0]; b.values[J] = l } continue } const U = Math.round(H), Y = Math.round(B); for (let j = 0; j < p; j++) { const J = j + U * C[2] + Y * C[1] + V * C[0], nt = j + K * w[2] + O * w[1] + k * w[0]; b.values[nt] = y[J] } } } } return e.makeTensorInfo(b.shape, b.dtype, b.values) } const GE = { kernelName: lu, backendName: "cpu", kernelFunc: $E };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function LE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, exclusive: i, reverse: a } = s; it(o, "cumprod"); const c = Yt([r], o.shape.length); let l = o; c != null && (l = Ae({ inputs: { x: o }, backend: e, attrs: { perm: c } })); const u = te(1, o.shape.length)[0]; if (u !== l.shape.length - 1) throw new Error(`backend.cumprod in CPU expects an inner-most axis=${l.shape.length - 1} but got axis=${u}`); const d = Ze(l.dtype, "int32"), h = Ul(Z(l.shape), d), p = e.data.get(l.dataId).values, f = l.shape[l.shape.length - 1], m = a ? (b, x) => b + f - x - 1 : (b, x) => b + x; for (let b = 0; b < p.length; b += f)for (let x = 0; x < f; x++) { const I = m(b, x); if (x === 0) h[I] = i ? 1 : p[I]; else { const y = m(b, x - 1); h[I] = i ? p[y] * h[y] : p[I] * h[y] } } const g = e.makeTensorInfo(l.shape, d, h); if (c != null) { const b = ys(c), x = Ae({ inputs: { x: g }, backend: e, attrs: { perm: b } }); return e.disposeIntermediateTensorInfo(g), e.disposeIntermediateTensorInfo(l), x } return g } const EE = { kernelName: cu, backendName: "cpu", kernelFunc: LE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function DE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, exclusive: i, reverse: a } = s; it(o, "cumsum"); const c = Yt([r], o.shape.length); let l = o; c != null && (l = Ae({ inputs: { x: o }, backend: e, attrs: { perm: c } })); const u = te(1, o.shape.length)[0]; if (u !== l.shape.length - 1) throw new Error(`backend.cumsum in CPU expects an inner-most axis=${l.shape.length - 1} but got axis=${u}`); const d = Ze(l.dtype, "int32"), h = Se(Z(l.shape), d), p = e.data.get(l.dataId).values, f = l.shape[l.shape.length - 1], m = a ? (b, x) => b + f - x - 1 : (b, x) => b + x; for (let b = 0; b < p.length; b += f)for (let x = 0; x < f; x++) { const I = m(b, x); if (x === 0) h[I] = i ? 0 : p[I]; else { const y = m(b, x - 1); h[I] = i ? p[y] + h[y] : p[I] + h[y] } } const g = e.makeTensorInfo(l.shape, d, h); if (c != null) { const b = ys(c), x = Ae({ inputs: { x: g }, backend: e, attrs: { perm: b } }); return e.disposeIntermediateTensorInfo(g), e.disposeIntermediateTensorInfo(l), x } return g } const WE = { kernelName: Na, backendName: "cpu", kernelFunc: DE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ME(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, weights: r } = t, { size: i, binaryOutput: a } = s; if (o.shape.length === 1) { const c = e.data.get(o.dataId).values, l = e.data.get(r.dataId).values, u = op(c, l, r.dtype, r.shape, i); return e.makeTensorInfo([i], r.dtype, u) } else if (o.shape.length === 2) { const c = e.bufferSync(o), l = e.bufferSync(r), u = Dx(c, l, i, a); return e.makeTensorInfo(u.shape, r.dtype, u.values) } throw new Error(`Error in denseBincount: input must be at most rank 2, but got rank${o.shape.length}.`) } const FE = { kernelName: uu, backendName: "cpu", kernelFunc: ME };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function VE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockSize: r, dataFormat: i } = s; v(i === "NHWC", () => `Only NHWC dataFormat supported on CPU for depthToSpace. Got ${i}`); const a = o.shape[0], c = o.shape[1], l = o.shape[2], u = o.shape[3], d = c * r, h = l * r, p = u / (r * r), f = e.data.get(o.dataId).values, m = new Float32Array(a * d * h * p); let g = 0; for (let b = 0; b < a; ++b)for (let x = 0; x < d; ++x) { const I = Math.floor(x / r), y = x % r; for (let C = 0; C < h; ++C) { const w = Math.floor(C / r), k = C % r, S = (y * r + k) * p; for (let T = 0; T < p; ++T) { const G = T + S + u * (w + l * (I + c * b)); m[g++] = f[G] } } } return e.makeTensorInfo([a, d, h, p], o.dtype, m) } const zE = { kernelName: du, backendName: "cpu", kernelFunc: VE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Wy(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dilations: c, dimRoundingMode: l } = s; it([o, r], "depthwiseConv2DNative"); const u = ct(o.shape), d = ct(r.shape); let h = c; h == null && (h = [1, 1]), v(Te(i, h), () => `Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${i} and dilations '${h}'`); const p = ye(o.shape, r.shape, i, h, a, l, !0), { filterHeight: f, filterWidth: m, dilationHeight: g, dilationWidth: b, padInfo: x } = p, I = x.left, y = x.top, C = p.outChannels / p.inChannels, w = new ke(p.outShape, o.dtype), k = e.data.get(o.dataId).values, S = e.data.get(r.dataId).values, T = w.values; for (let R = 0; R < p.batchSize; ++R) { const G = R * u[0], F = R * w.strides[0]; for (let V = 0; V < p.outHeight; ++V) { const z = F + V * w.strides[1], X = V * p.strideHeight - y; for (let O = 0; O < f; ++O) { const B = X + O * g; if (B < 0 || B >= p.inHeight) continue; const K = O * d[0], H = G + B * u[1]; for (let U = 0; U < p.outWidth; ++U) { const Y = z + U * w.strides[2], j = U * p.strideWidth - I; for (let J = 0; J < m; ++J) { const nt = j + J * b; if (nt < 0 || nt >= p.inWidth) continue; const q = K + J * d[1], rt = H + nt * p.inChannels; let lt = Y, pt = q; for (let ht = 0; ht < p.inChannels; ++ht) { const xt = k[rt + ht]; for (let yt = 0; yt < C; ++yt)T[lt + yt] += xt * S[pt + yt]; lt += C, pt += C } } } } } } return e.makeTensorInfo(w.shape, w.dtype, w.values) } const XE = { kernelName: Ra, backendName: "cpu", kernelFunc: Wy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function AE(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, dilations: a, pad: c, dimRoundingMode: l, filterShape: u } = s; it([o, r], "depthwiseConv2dNativeBackpropFilter"); const d = ye(o.shape, u, i, a, c, l, !0), { strideHeight: h, strideWidth: p, filterHeight: f, filterWidth: m } = d, g = new ke(d.filterShape, "float32"), b = d.padInfo.left, x = d.padInfo.top, I = d.outChannels / d.inChannels, y = e.data.get(o.dataId).values, C = new ke(o.shape, o.dtype, y), w = e.data.get(r.dataId).values, k = new ke(r.shape, r.dtype, w); for (let S = 0; S < f; ++S) { const T = Math.max(0, Math.ceil((x - S) / h)), R = Math.min(d.outHeight, (d.inHeight + x - S) / h); for (let G = 0; G < m; ++G) { const F = Math.max(0, Math.ceil((b - G) / p)), V = Math.min(d.outWidth, (d.inWidth + b - G) / p); for (let z = 0; z < d.outChannels; ++z) { const X = Math.trunc(z / I), O = z % I; let B = 0; for (let K = 0; K < d.batchSize; ++K)for (let H = T; H < R; ++H) { const U = S + H * h - x; for (let Y = F; Y < V; ++Y) { const j = G + Y * p - b; B += C.get(K, U, j, X) * k.get(K, H, Y, z) } } g.set(B, S, G, X, O) } } } return e.makeTensorInfo(g.shape, g.dtype, g.values) } const OE = { kernelName: hu, backendName: "cpu", kernelFunc: AE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function PE(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { strides: i, dilations: a, pad: c, dimRoundingMode: l, inputShape: u } = s; it([o, r], "depthwiseConv2DNativeBackpropInput"); const d = ct(o.shape), h = ct(r.shape), p = ye(u, r.shape, i, a, c, l, !0), f = new ke(p.inShape, "float32"), m = f.values, [g, b, x] = f.strides, I = e.data.get(o.dataId).values, [y, C, w] = d, k = e.data.get(r.dataId).values, [S, T, R] = h, { batchSize: G, filterHeight: F, filterWidth: V, inChannels: z, inHeight: X, inWidth: O, outChannels: B, outHeight: K, outWidth: H, strideHeight: U, strideWidth: Y } = p, j = F - 1 - p.padInfo.top, J = V - 1 - p.padInfo.left, nt = B / z; for (let q = 0; q < G; ++q)for (let rt = 0; rt < z; ++rt)for (let lt = 0; lt < X; ++lt) { const pt = lt - j, ht = Math.max(0, Math.ceil(pt / U)), xt = Math.min(K, (F + pt) / U); for (let yt = 0; yt < O; ++yt) { const Et = yt - J, At = Math.max(0, Math.ceil(Et / Y)), jt = Math.min(H, (V + Et) / Y); let Ot = 0; for (let Dt = ht; Dt < xt; ++Dt) { const Jt = Dt * U - pt; for (let Ut = At; Ut < jt; ++Ut) { const ls = Ut * Y - Et, ve = y * q + C * Dt + w * Ut, Ms = S * (F - 1 - Jt) + T * (V - 1 - ls) + R * rt; for (let cn = 0; cn < nt; ++cn) { const To = rt * nt + cn, Fn = I[ve + To], us = k[Ms + cn]; Ot += Fn * us } } } m[g * q + b * lt + x * yt + rt] = Ot } } return e.makeTensorInfo(f.shape, f.dtype, f.values) } const KE = { kernelName: pu, backendName: "cpu", kernelFunc: PE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ZE(n) { const { inputs: t, backend: e } = n, { x: s } = t, o = Z(s.shape), r = e.data.get(s.dataId).values, i = Ct([o, o], s.dtype), a = i.values; for (let l = 0; l < r.length; l++)a[l * o + l] = r[l]; const c = [...s.shape, ...s.shape]; return e.makeTensorInfo(c, i.dtype, i.values) } const BE = { kernelName: hf, backendName: "cpu", kernelFunc: ZE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const HE = { kernelName: $a, backendName: "cpu", kernelFunc: ({ inputs: n, backend: t, attrs: e }) => { const { x: s, filter: o } = n, { strides: r, pad: i, dilations: a } = e, c = t, l = c.data.get(s.dataId).values, u = s.shape.length, d = c.data.get(o.dataId).values, h = o.shape.length, { batchSize: p, inHeight: f, inWidth: m, inChannels: g, outHeight: b, outWidth: x, padInfo: I, strideHeight: y, strideWidth: C, filterHeight: w, filterWidth: k, dilationHeight: S, dilationWidth: T, outShape: R } = Ii(s.shape, o.shape, r, i, "NHWC", a), G = Z(R), F = R.length, V = ne(s.dtype, G); for (let X = 0; X < p; ++X)for (let O = 0; O < b; ++O) { const B = O * y - I.top; for (let K = 0; K < x; ++K) { const H = K * C - I.left; for (let U = 0; U < g; ++U) { let Y = Number.MIN_SAFE_INTEGER; for (let J = 0; J < w; ++J) { const nt = B + J * S; if (nt >= 0 && nt < f) for (let q = 0; q < k; ++q) { const rt = H + q * T; if (rt >= 0 && rt < m) { const lt = Vn([X, nt, rt, U], u, ct(s.shape)), pt = Vn([J, q, U], h, ct(o.shape)), ht = l[lt] + d[pt]; ht > Y && (Y = ht) } } } const j = Vn([X, O, K, U], F, ct(R)); V[j] = Y } } } return { dataId: c.write(Bs(V, s.dtype), R, s.dtype), shape: R, dtype: s.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _E = { kernelName: mu, backendName: "cpu", kernelFunc: ({ inputs: n, backend: t, attrs: e }) => { const { x: s, filter: o, dy: r } = n, { strides: i, pad: a, dilations: c } = e, l = t, u = wn(s.shape, l.data.get(s.dataId).values), d = wn(o.shape, l.data.get(o.dataId).values), { batchSize: h, inHeight: p, inWidth: f, inChannels: m, outHeight: g, outWidth: b, padInfo: x, strideHeight: I, strideWidth: y, filterHeight: C, filterWidth: w, dilationHeight: k, dilationWidth: S, outShape: T } = Ii(s.shape, o.shape, i, a, "NHWC", c); v(r.rank === T.length, () => `Error in ${mu}, dy must have the same rank as output ${T.length}, but got ${r.rank}`); const R = wn(T, l.data.get(r.dataId).values), G = af(o.shape, o.dtype); for (let V = 0; V < h; ++V)for (let z = 0; z < g; ++z) { const X = z * I - x.top; for (let O = 0; O < b; ++O) { const B = O * y - x.left; for (let K = 0; K < m; ++K) { let H = Number.MIN_SAFE_INTEGER, U = 0, Y = 0; for (let j = 0; j < C; ++j) { const J = X + j * k; if (J >= 0 && J < p) for (let nt = 0; nt < w; ++nt) { const q = B + nt * S; if (q >= 0 && q < f) { const rt = u[V][J][q][K] + d[j][nt][K]; rt > H && (H = rt, U = j, Y = nt) } } } G[U][Y][K] += R[V][z][O][K] } } } return { dataId: l.write(Bs(G, s.dtype), o.shape, o.dtype), shape: o.shape, dtype: o.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const UE = { kernelName: fu, backendName: "cpu", kernelFunc: ({ inputs: n, backend: t, attrs: e }) => { const { x: s, filter: o, dy: r } = n, { strides: i, pad: a, dilations: c } = e, l = t, u = wn(s.shape, l.data.get(s.dataId).values), d = wn(o.shape, l.data.get(o.dataId).values), { batchSize: h, inHeight: p, inWidth: f, inChannels: m, outHeight: g, outWidth: b, padInfo: x, strideHeight: I, strideWidth: y, filterHeight: C, filterWidth: w, dilationHeight: k, dilationWidth: S, outShape: T } = Ii(s.shape, o.shape, i, a, "NHWC", c); v(r.rank === T.length, () => `Error in ${fu}, dy must have the same rank as output ${T.length}, but got ${r.rank}`); const R = wn(T, l.data.get(r.dataId).values), G = af(s.shape, s.dtype); for (let V = 0; V < h; ++V)for (let z = 0; z < g; ++z) { const X = z * I - x.top; for (let O = 0; O < b; ++O) { const B = O * y - x.left; for (let K = 0; K < m; ++K) { let H = Number.MIN_SAFE_INTEGER, U = X < 0 ? 0 : X, Y = B < 0 ? 0 : B; for (let j = 0; j < C; ++j) { const J = X + j * k; if (J >= 0 && J < p) for (let nt = 0; nt < w; ++nt) { const q = B + nt * S; if (q >= 0 && q < f) { const rt = u[V][J][q][K] + d[j][nt][K]; rt > H && (H = rt, U = J, Y = q) } } } G[V][U][Y][K] += R[V][z][O][K] } } } return { dataId: l.write(Bs(G, s.dtype), s.shape, s.dtype), shape: s.shape, dtype: s.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Yi(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; it(o, "sum"); let a; o.dtype === "bool" ? a = Gs({ inputs: { x: o }, backend: e, attrs: { dtype: "int32" } }) : a = Un({ inputs: { x: o }, backend: e }); const c = a.shape.length, l = It(r, a.shape), u = Yt(l, c); let d = l, h = a; u != null && (h = Ae({ inputs: { x: a }, backend: e, attrs: { perm: u } }), d = te(d.length, c)), Ie("sum", d, h.shape.length); const [p, f] = fe(h.shape, d), m = Ze(h.dtype, "int32"); let g = ll(e, p, m); const b = Z(f), x = e.data.get(g.dataId).values, I = e.data.get(h.dataId).values; for (let y = 0; y < x.length; ++y) { const C = y * b; let w = 0; for (let k = 0; k < b; ++k)w += I[C + k]; x[y] = w } if (i) { const y = oe(g.shape, l), C = g; g = zt({ inputs: { x: g }, backend: e, attrs: { shape: y } }), e.disposeIntermediateTensorInfo(C) } return e.disposeIntermediateTensorInfo(a), u != null && e.disposeIntermediateTensorInfo(h), g } const YE = { kernelName: cc, backendName: "cpu", kernelFunc: Yi };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QE(n) { const { inputs: t, backend: e, attrs: s } = n, { equation: o } = s, r = t, { allDims: i, summedDims: a, idDims: c } = dh(o, r.length); ph(i.length, c, r); const { path: l, steps: u } = fh(a, c), d = u.length; let h = null, p = i.length; const f = []; for (let m = 0; m < d; ++m) { for (const g of u[m]) { const { permutationIndices: b, expandDims: x } = hh(p, c[g]); let I; mh(b) ? I = r[g] : (I = Ae({ inputs: { x: r[g] }, backend: e, attrs: { perm: b } }), f.push(I)); const y = I.shape.slice(); for (let C = 0; C < x.length; ++C)y.splice(x[C], 0, 1); Rt(I.shape, y) || (I = zt({ inputs: { x: I }, backend: e, attrs: { shape: y } }), f.push(I)), h === null ? h = I : (h = ul({ inputs: { a: I, b: h }, backend: e }), f.push(h)) } m < d - 1 && (l[m] >= 0 && (h = Yi({ inputs: { x: h }, backend: e, attrs: { axis: l[m] - (i.length - p), keepDims: !1 } }), f.push(h)), p--) } for (const m of f) m !== h && e.disposeIntermediateTensorInfo(m); return h } const JE = { kernelName: pf, backendName: "cpu", kernelFunc: QE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jE(n) { const { inputs: t, backend: e } = n, { dy: s, y: o } = t; it([s, o], "eluGrad"); const r = new Float32Array(Z(o.shape)), i = e.data.get(o.dataId).values, a = e.data.get(s.dataId).values; for (let c = 0; c < i.length; ++c) { const l = i[c]; l >= 1 ? r[c] = a[c] : r[c] = a[c] * (l + 1) } return e.makeTensorInfo(o.shape, "float32", r) } const qE = { kernelName: gu, backendName: "cpu", kernelFunc: jE };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const t3 = sh, e3 = oh, n3 = rh, s3 = ih, o3 = ah, r3 = ch, i3 = Lt(Dr, n => { const t = Math.sign(n), e = Math.abs(n), s = 1 / (1 + t3 * e); return t * (1 - ((((r3 * s + o3) * s + s3) * s + n3) * s + e3) * s * Math.exp(-e * e)) }), a3 = { kernelName: Dr, backendName: "cpu", kernelFunc: i3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pl(n) { const { inputs: t, backend: e, attrs: s } = n, { input: o } = t, { dim: r } = s, i = o.shape.length, a = o.shape.slice(); let c = r; return r < 0 && (v(-(i + 1) <= r, () => `Axis must be in the interval [${-(i + 1)}, ${i}]`), c = i + r + 1), a.splice(c, 0, 1), zt({ inputs: { x: o }, backend: e, attrs: { shape: a } }) } const c3 = { kernelName: La, backendName: "cpu", kernelFunc: pl };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const l3 = ae((n, t) => n / t), up = be(Lr, l3), dp = { kernelName: Lr, backendName: "cpu", kernelFunc: up };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function My(n, t, e) { const s = n.shape, o = s[0], r = s[1], i = e.data.get(n.dataId), a = i.complexTensorInfos.real, c = i.complexTensorInfos.imag, l = [o, r], u = Z(l), d = xe("float32", u), h = xe("float32", u); for (let g = 0; g < o; g++) { const b = xo({ inputs: { x: a }, backend: e, attrs: { begin: [g, 0], size: [1, r] } }), x = xo({ inputs: { x: c }, backend: e, attrs: { begin: [g, 0], size: [1, r] } }), I = Ue({ inputs: { real: b, imag: x }, backend: e }), { real: y, imag: C } = u3(I, t, e), w = rs(y, C); for (let k = 0; k < r; k++) { const S = lh(w, k); d[g * r + k] = S.real, h[g * r + k] = S.imag } e.disposeIntermediateTensorInfo(b), e.disposeIntermediateTensorInfo(x), e.disposeIntermediateTensorInfo(I) } const p = e.makeTensorInfo(l, "float32", d), f = e.makeTensorInfo(l, "float32", h), m = Ue({ inputs: { real: p, imag: f }, backend: e }); return e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), m } function u3(n, t, e) { const s = Z(n.shape), o = e.data.get(n.dataId), r = e.data.get(o.complexTensorInfos.real.dataId).values, i = e.data.get(o.complexTensorInfos.imag.dataId).values; if (d3(s)) { const a = hp(r, i, s, t, e), c = [n.shape[0], n.shape[1]]; if (t) { const l = e.makeTensorInfo(c, "float32", a.real), u = e.makeTensorInfo(c, "float32", a.imag), d = e.makeTensorInfo([], "float32", ps(s, "float32")), h = Un({ inputs: { x: d }, backend: e }), p = dp.kernelFunc({ inputs: { a: l, b: d }, backend: e }), f = dp.kernelFunc({ inputs: { a: u, b: h }, backend: e }), m = e.data.get(p.dataId).values, g = e.data.get(f.dataId).values; return e.disposeIntermediateTensorInfo(l), e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), { real: m, imag: g } } return a } else { const a = rs(r, i), c = h3(a, s, t); return Ig(c) } } function d3(n) { return (n & n - 1) === 0 } function hp(n, t, e, s, o) { if (e === 1) return { real: n, imag: t }; const r = rs(n, t), i = e / 2, a = Cg(r), c = a.real, l = a.imag, u = [c.length], d = o.makeTensorInfo(u, "float32", c), h = o.makeTensorInfo(u, "float32", l), p = Ue({ inputs: { real: d, imag: h }, backend: o }), f = wg(r), m = f.real, g = f.imag, b = [m.length], x = o.makeTensorInfo(b, "float32", m), I = o.makeTensorInfo(b, "float32", g), y = Ue({ inputs: { real: x, imag: I }, backend: o }), C = hp(c, l, i, s, o), w = C.real, k = C.imag, S = [w.length], T = o.makeTensorInfo(S, "float32", w), R = o.makeTensorInfo(S, "float32", k), G = Ue({ inputs: { real: T, imag: R }, backend: o }), F = hp(m, g, i, s, o), V = F.real, z = F.imag, X = [V.length], O = o.makeTensorInfo(X, "float32", V), B = o.makeTensorInfo(X, "float32", z), K = Ue({ inputs: { real: O, imag: B }, backend: o }), H = Sg(e, s), U = [H.real.length], Y = o.makeTensorInfo(U, "float32", H.real), j = o.makeTensorInfo(U, "float32", H.imag), J = Ue({ inputs: { real: Y, imag: j }, backend: o }), nt = ul({ inputs: { a: J, b: K }, backend: o }), q = qo({ inputs: { a: G, b: nt }, backend: o }), rt = cp({ inputs: { a: G, b: nt }, backend: o }), lt = bo({ inputs: { input: q }, backend: o }), pt = bo({ inputs: { input: rt }, backend: o }), ht = nr({ inputs: { input: q }, backend: o }), xt = nr({ inputs: { input: rt }, backend: o }), yt = sr({ inputs: [lt, pt], backend: o, attrs: { axis: 0 } }), Et = sr({ inputs: [ht, xt], backend: o, attrs: { axis: 0 } }), At = o.data.get(yt.dataId).values, jt = o.data.get(Et.dataId).values; return o.disposeIntermediateTensorInfo(d), o.disposeIntermediateTensorInfo(h), o.disposeIntermediateTensorInfo(p), o.disposeIntermediateTensorInfo(x), o.disposeIntermediateTensorInfo(I), o.disposeIntermediateTensorInfo(y), o.disposeIntermediateTensorInfo(T), o.disposeIntermediateTensorInfo(R), o.disposeIntermediateTensorInfo(G), o.disposeIntermediateTensorInfo(O), o.disposeIntermediateTensorInfo(B), o.disposeIntermediateTensorInfo(K), o.disposeIntermediateTensorInfo(Y), o.disposeIntermediateTensorInfo(j), o.disposeIntermediateTensorInfo(J), o.disposeIntermediateTensorInfo(nt), o.disposeIntermediateTensorInfo(q), o.disposeIntermediateTensorInfo(rt), o.disposeIntermediateTensorInfo(lt), o.disposeIntermediateTensorInfo(ht), o.disposeIntermediateTensorInfo(pt), o.disposeIntermediateTensorInfo(xt), o.disposeIntermediateTensorInfo(yt), o.disposeIntermediateTensorInfo(Et), { real: At, imag: jt } } function h3(n, t, e) { const s = new Float32Array(t * 2); for (let o = 0; o < t; o++) { let r = 0, i = 0; for (let a = 0; a < t; a++) { const c = kg(o * a, t, e), l = lh(n, a); r += l.real * c.real - l.imag * c.imag, i += l.real * c.imag + l.imag * c.real } e && (r /= t, i /= t), vg(s, r, i, o) } return s }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function p3(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = Z(s.shape), r = s.shape[s.shape.length - 1], i = o / r, a = zt({ inputs: { x: s }, backend: e, attrs: { shape: [i, r] } }), c = My(a, !1, e), l = zt({ inputs: { x: c }, backend: e, attrs: { shape: s.shape } }); return e.disposeIntermediateTensorInfo(a), e.disposeIntermediateTensorInfo(c), l } const f3 = { kernelName: bu, backendName: "cpu", kernelFunc: p3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pp(n) { const { backend: t, attrs: e } = n, { shape: s, value: o, dtype: r } = e, i = r || xr(o), a = ne(i, Z(s)); return g3(a, o, i), t.makeTensorInfo(s, i, a) } const m3 = { kernelName: xu, backendName: "cpu", kernelFunc: pp }; function g3(n, t, e) { n.fill(t) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const b3 = { kernelName: yu, backendName: "cpu", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { image: s } = n, o = e, r = xe(s.dtype, Z(s.shape)), [i, a, c, l] = s.shape, u = o.data.get(s.dataId).values; for (let h = 0; h < i; h++) { const p = h * c * a * l; for (let f = 0; f < a; f++) { const m = f * (c * l); for (let g = 0; g < c; g++) { const b = g * l; for (let x = 0; x < l; x++) { const I = Math.round(c - g - 1), y = p + m + b + x; let C = u[y]; if (I >= 0 && I < c) { const w = I * l, k = p + m + w + x; C = u[k] } r[y] = C } } } } return { dataId: o.write(r, s.shape, s.dtype), shape: s.shape, dtype: s.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const x3 = ae((n, t) => Math.floor(n / t)), y3 = be(Vr, x3, null, "int32"), I3 = { kernelName: Vr, backendName: "cpu", kernelFunc: y3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function C3(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r, bias: i, preluActivationWeights: a } = t, { strides: c, pad: l, dataFormat: u, dilations: d, dimRoundingMode: h, activation: p, leakyreluAlpha: f } = s; let m = Dy({ inputs: { x: o, filter: r }, backend: e, attrs: { strides: c, pad: l, dataFormat: u, dilations: d, dimRoundingMode: h } }); if (i) { const g = m; if (u === "NCHW" && i.shape.length === 1 && i.shape[0] !== 1) { const b = zt({ inputs: { x: i }, backend: e, attrs: { shape: [i.shape[0], 1, 1] } }); m = qo({ inputs: { a: m, b }, backend: e }), e.disposeIntermediateTensorInfo(b) } else m = qo({ inputs: { a: m, b: i }, backend: e }); e.disposeIntermediateTensorInfo(g) } if (p) { const g = m; if (u === "NCHW" && p === "prelu" && a.shape.length === 1 && a.shape[0] !== 1) { const b = zt({ inputs: { x: a }, backend: e, attrs: { shape: [a.shape[0], 1, 1] } }); m = hl(e, m, p, b, f), e.disposeIntermediateTensorInfo(b) } else m = hl(e, m, p, a, f); e.disposeIntermediateTensorInfo(g) } return m } const w3 = { kernelName: gc, backendName: "cpu", kernelFunc: C3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function v3(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r, bias: i, preluActivationWeights: a } = t, { strides: c, pad: l, dataFormat: u, dilations: d, dimRoundingMode: h, activation: p, leakyreluAlpha: f } = s; let m = Wy({ inputs: { x: o, filter: r }, backend: e, attrs: { strides: c, pad: l, dataFormat: u, dilations: d, dimRoundingMode: h } }); if (i) { const g = m; m = qo({ inputs: { a: m, b: i }, backend: e }), e.disposeIntermediateTensorInfo(g) } if (p) { const g = m; m = hl(e, m, p, a, f), e.disposeIntermediateTensorInfo(g) } return m } const S3 = { kernelName: Lf, backendName: "cpu", kernelFunc: v3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function k3(n) { const { inputs: t, backend: e } = n, { params: s, indices: o } = t, r = Z(s.shape), i = o.shape, a = i[i.length - 1], [c, l, u, d] = Bd(s, o); if (l === 0) return e.makeTensorInfo(c, s.dtype, []); const h = e.data.get(o.dataId).values, p = e.bufferSync(s), f = Px(h, p, s.dtype, l, a, u, d, s.shape, r); return e.makeTensorInfo(c, s.dtype, f.values) } const T3 = { kernelName: ff, backendName: "cpu", kernelFunc: k3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function N3(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, indices: r } = t, { axis: i, batchDims: a } = s; it([o, r], "gatherV2"); const c = It(i, o.shape)[0], l = e.data.get(r.dataId).values, u = o.shape[c]; for (let y = 0; y < l.length; ++y) { const C = l[y]; v(C <= u - 1 && C >= 0, () => `GatherV2: the index value ${C} is not in [0, ${u - 1}]`) } let d = a; a == null && (d = 0); const h = Z(r.shape), p = xh(o, r, c, d), f = zt({ inputs: { x: o }, backend: e, attrs: { shape: [p.batchSize, p.outerSize, p.dimSize, p.sliceSize] } }), m = zt({ inputs: { x: r }, backend: e, attrs: { shape: [p.batchSize, h / p.batchSize] } }), g = [p.batchSize, p.outerSize, h / p.batchSize, p.sliceSize], b = e.bufferSync(m), x = e.bufferSync(f), I = Kx(x, b, g); return e.disposeIntermediateTensorInfo(f), e.disposeIntermediateTensorInfo(m), e.makeTensorInfo(p.outputShape, I.dtype, I.values) } const R3 = { kernelName: Da, backendName: "cpu", kernelFunc: N3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $3(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = Z(s.shape), r = s.shape[s.shape.length - 1], i = o / r, a = zt({ inputs: { x: s }, backend: e, attrs: { shape: [i, r] } }), c = My(a, !0, e), l = zt({ inputs: { x: c }, backend: e, attrs: { shape: s.shape } }); return e.disposeIntermediateTensorInfo(a), e.disposeIntermediateTensorInfo(c), l } const G3 = { kernelName: Iu, backendName: "cpu", kernelFunc: $3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const L3 = Lt(Ar, n => Number.isFinite(n) ? 1 : 0, "bool"), E3 = { kernelName: Ar, backendName: "cpu", kernelFunc: L3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const D3 = Lt(Or, n => Math.abs(n) === 1 / 0 ? 1 : 0, "bool"), W3 = { kernelName: Or, backendName: "cpu", kernelFunc: D3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const M3 = Lt(Pr, n => Number.isNaN(n) ? 1 : 0, "bool"), F3 = { kernelName: Pr, backendName: "cpu", kernelFunc: M3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function V3(n) { const { backend: t, attrs: e } = n, { start: s, stop: o, num: r } = e, i = Ux(s, o, r); return t.makeTensorInfo([i.length], "float32", i) } const z3 = { kernelName: mf, backendName: "cpu", kernelFunc: V3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const X3 = Lt(Zr, n => Math.log1p(n)), A3 = { kernelName: Zr, backendName: "cpu", kernelFunc: X3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const O3 = ae((n, t) => n && t), P3 = be(za, O3, null, "bool"), K3 = { kernelName: za, backendName: "cpu", kernelFunc: P3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Z3 = Lt(Xa, n => n ? 0 : 1, "bool"), B3 = { kernelName: Xa, backendName: "cpu", kernelFunc: Z3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const H3 = ae((n, t) => n || t), _3 = be(Aa, H3, null, "bool"), U3 = { kernelName: Aa, backendName: "cpu", kernelFunc: _3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Y3(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { depthRadius: r, bias: i, alpha: a, beta: c } = s; it(o, "LRN"); const l = o.shape[3], u = l - 1, d = e.data.get(o.dataId).values, h = Z(o.shape), p = new Float32Array(h); function f(m) { const g = m % l; let b = m - g + Math.max(0, g - r); const x = m - g + Math.min(g + r, u); let I = 0; for (; b <= x; b++) { const y = d[b]; I += y * y } return I } for (let m = 0; m < h; m++) { const g = f(m), b = d[m] * Math.pow(i + a * g, -c); p[m] = b } return e.makeTensorInfo(o.shape, o.dtype, p) } const Q3 = { kernelName: Oa, backendName: "cpu", kernelFunc: Y3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function J3(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, y: r, dy: i } = t, { depthRadius: a, bias: c, alpha: l, beta: u } = s; it(i, "LRNGrad"); const d = Z(i.shape), h = i.shape[3], p = e.data.get(i.dataId).values, f = e.data.get(o.dataId).values, m = e.data.get(r.dataId).values, g = new Float32Array(d), b = d; for (let x = 0; x < b; x++) { const I = x % h, y = x - I + Math.max(0, I - a), C = x - I + Math.min(h, I + a + 1); let w = 0; for (let k = y; k < C; k++)w += Math.pow(f[k], 2); w = l * w + c; for (let k = y; k < C; k++) { let S = -2 * l * u * f[k] * m[x] / w; x === k && (S += Math.pow(w, -u)), S *= p[x], g[k] += S } } return e.makeTensorInfo(i.shape, o.dtype, g) } const j3 = { kernelName: wu, backendName: "cpu", kernelFunc: J3 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Fy(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { reductionIndices: r, keepDims: i } = s, a = e; let c = o.shape; const l = c.length, u = It(r, c); let d = u; const h = Yt(d, l); let p = a.data.get(o.dataId).values; if (h != null) { const y = new Array(l); for (let C = 0; C < y.length; C++)y[C] = c[h[C]]; p = ip(p, c, o.dtype, h, y), d = te(d.length, l), c = y } it(o, "max"), Ie("max", d, l); const [f, m] = fe(c, d), g = Z(m), b = Qx(p, g, f, o.dtype), x = a.write(b, f, o.dtype); let I = f; return i && (I = oe(f, u)), { dataId: x, shape: I, dtype: o.dtype } } const q3 = { kernelName: Pa, backendName: "cpu", kernelFunc: Fy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t; it(o, "maxPool"); const { filterSize: r, strides: i, pad: a, dimRoundingMode: c } = s, l = 1; v(Te(i, l), () => `Error in maxPool: Either strides or dilations must be 1. Got strides ${i} and dilations '${l}'`); const u = hn(o.shape, r, i, l, a, c); let d; if (u.filterWidth === 1 && u.filterHeight === 1 && Rt(u.inShape, u.outShape)) d = Un({ inputs: { x: o }, backend: e }); else { const h = e.data.get(o.dataId).values, p = ct(o.shape), f = lp(h, o.shape, o.dtype, p, u, "max"); d = e.makeTensorInfo(u.outShape, o.dtype, f.values) } return d } const eD = { kernelName: Ka, backendName: "cpu", kernelFunc: tD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { filterSize: r, strides: i, pad: a, dimRoundingMode: c, dataFormat: l } = s; it(o, "maxPool3d"); const u = ts(o.shape, r, i, 1, a, c, l), d = e.data.get(o.dataId).values, h = Ey(d, o.shape, o.dtype, ct(o.shape), u, "max"); return e.makeTensorInfo(h.shape, "float32", h.values) } const sD = { kernelName: Za, backendName: "cpu", kernelFunc: nD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function oD(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, { filterSize: i, strides: a, pad: c, dimRoundingMode: l } = s; it([o, r], "maxPool3DGrad"); const u = ts(r.shape, i, a, 1, c, l), d = e.bufferSync(r), h = HL(d, u), p = u.strideDepth, f = u.strideHeight, m = u.strideWidth, g = u.dilationDepth, b = u.dilationHeight, x = u.dilationWidth, I = u.effectiveFilterDepth, y = u.effectiveFilterHeight, C = u.effectiveFilterWidth, w = I - 1 - u.padInfo.front, k = C - 1 - u.padInfo.left, S = y - 1 - u.padInfo.top, T = Ct(r.shape, "float32"), R = e.bufferSync(o); for (let G = 0; G < u.batchSize; ++G)for (let F = 0; F < u.inChannels; ++F)for (let V = 0; V < u.inDepth; ++V)for (let z = 0; z < u.inHeight; ++z)for (let X = 0; X < u.inWidth; ++X) { const O = V - w, B = z - S, K = X - k; let H = 0; for (let U = 0; U < I; U += g) { const Y = (O + U) / p; if (!(Y < 0 || Y >= u.outDepth || Math.floor(Y) !== Y)) for (let j = 0; j < y; j += b) { const J = (B + j) / f; if (!(J < 0 || J >= u.outHeight || Math.floor(J) !== J)) for (let nt = 0; nt < C; nt += x) { const q = (K + nt) / m; if (q < 0 || q >= u.outWidth || Math.floor(q) !== q) continue; const rt = I * y * C - 1 - h.get(G, Y, J, q, F), lt = U * y * C + j * C + nt, pt = rt === lt ? 1 : 0; if (pt === 0) continue; const ht = R.get(G, Y, J, q, F); H += ht * pt } } } T.set(H, G, V, z, X, F) } return e.makeTensorInfo(T.shape, T.dtype, T.values) } const rD = { kernelName: Su, backendName: "cpu", kernelFunc: oD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function iD(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r, output: i } = t, a = r; it([r, i], "maxPoolGrad"); const { filterSize: c, strides: l, pad: u, dimRoundingMode: d } = s, h = hn(a.shape, c, l, 1, u, d), p = e.data.get(a.dataId).values, f = Ct(h.outShape, a.dtype, Ly(p, a.shape, a.dtype, h).values), m = h.strideHeight, g = h.strideWidth, b = h.dilationHeight, x = h.dilationWidth, I = h.effectiveFilterHeight, y = h.effectiveFilterWidth, C = y - 1 - h.padInfo.left, w = I - 1 - h.padInfo.top, k = Ct(a.shape, "float32"), S = e.data.get(o.dataId).values, T = Ct(o.shape, "float32", S); for (let R = 0; R < h.batchSize; ++R)for (let G = 0; G < h.inChannels; ++G)for (let F = 0; F < h.inHeight; ++F)for (let V = 0; V < h.inWidth; ++V) { const z = F - w, X = V - C; let O = 0; for (let B = 0; B < I; B += b) { const K = (z + B) / m; if (!(K < 0 || K >= h.outHeight || Math.floor(K) !== K)) for (let H = 0; H < y; H += x) { const U = (X + H) / g; if (U < 0 || U >= h.outWidth || Math.floor(U) !== U) continue; const Y = I * y - 1 - f.get(R, K, U, G), j = B * y + H, J = Y === j ? 1 : 0; if (J === 0) continue; const nt = T.get(R, K, U, G); O += nt * J } } k.set(O, R, F, V, G) } return e.makeTensorInfo(k.shape, k.dtype, k.values) } const aD = { kernelName: vu, backendName: "cpu", kernelFunc: iD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function cD(n, t, e, s, o) { const r = ct(t), i = lp(n, t, e, r, o, "max"), a = Ly(n, t, e, o, !0, s); return [i.values, a.values] }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const lD = { kernelName: gf, backendName: "cpu", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { x: s } = n, { filterSize: o, strides: r, pad: i, includeBatchInIndex: a } = t, c = e; it(s, "MaxPoolWithArgmax"); const l = c.data.get(s.dataId).values, u = hn(s.shape, o, r, [1, 1], i), [d, h] = cD(l, s.shape, s.dtype, a, u), p = c.write(d, u.outShape, s.dtype), f = c.write(h, u.outShape, s.dtype); return [{ dataId: p, shape: u.outShape, dtype: s.dtype }, { dataId: f, shape: u.outShape, dtype: "int32" }] } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function uD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s, a = It(r, o.shape), l = fe(o.shape, a)[1], u = Z(l), d = [], h = e.makeTensorInfo([], "float32", new Float32Array([u])); d.push(h); const p = Gs({ inputs: { x: o }, backend: e, attrs: { dtype: "float32" } }); d.push(p); const f = up({ inputs: { a: p, b: h }, backend: e }); d.push(f); const m = Yi({ inputs: { x: f }, backend: e, attrs: { axis: r, keepDims: i } }); return d.forEach(g => e.disposeIntermediateTensorInfo(g)), m } const dD = { kernelName: Ba, backendName: "cpu", kernelFunc: uD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; it(o, "min"); const a = It(r, o.shape); let c = a; const l = Yt(c, o.shape.length); let u = o; l != null && (u = Ae({ inputs: { x: o }, backend: e, attrs: { perm: l } }), c = te(c.length, o.shape.length)), Ie("min", c, u.shape.length); const [d, h] = fe(u.shape, c), p = Z(h), f = Se(Z(d), u.dtype), m = e.data.get(u.dataId).values; for (let b = 0; b < f.length; ++b) { const x = b * p; let I = m[x]; for (let y = 0; y < p; ++y) { const C = m[x + y]; (Number.isNaN(C) || C < I) && (I = C) } f[b] = I } l != null && e.disposeIntermediateTensorInfo(u); const g = e.makeTensorInfo(d, u.dtype, f); if (i) { const b = oe(d, a), x = zt({ inputs: { x: g }, backend: e, attrs: { shape: b } }); return e.disposeIntermediateTensorInfo(g), x } return g } const pD = { kernelName: Ha, backendName: "cpu", kernelFunc: hD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { paddings: r, mode: i } = s; it(o, "mirrorPad"); const a = r.map((I, y) => I[0] + o.shape[y] + I[1]), c = r.map(I => I[0]), l = r.map((I, y) => I[0] + o.shape[y]), u = i === "reflect" ? 0 : 1, d = e.data.get(o.dataId).values, h = o.shape.length, p = ct(o.shape), f = Z(a), m = a.length, g = ct(a), b = xe(o.dtype, f); for (let I = 0; I < f; I++) { let y = Go(I, m, g); for (let w = 0; w < m; w++)y[w] < c[w] ? y[w] = c[w] * 2 - y[w] - u : y[w] >= l[w] && (y[w] = (l[w] - 1) * 2 - y[w] + u); y = y.map((w, k) => w - c[k]); const C = Vn(y, h, p); b[I] = d[C] } return { dataId: e.write(b, a, o.dtype), shape: a, dtype: o.dtype } } const mD = { kernelName: _a, backendName: "cpu", kernelFunc: fD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const gD = ae((n, t) => { const e = n % t; return n < 0 && t < 0 || n >= 0 && t >= 0 ? e : (e + t) % t }), bD = be(_r, gD), xD = { kernelName: _r, backendName: "cpu", kernelFunc: bD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Vy(n) { const { inputs: t, backend: e, attrs: s } = n, { logits: o } = t, { dim: r } = s, i = o.shape.length; let a = r; if (a === -1 && (a = i - 1), a !== i - 1) throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${i} and dim was ${a}`); const c = It([a], o.shape), l = Fy({ inputs: { x: o }, backend: e, attrs: { reductionIndices: c, keepDims: !1 } }), u = oe(l.shape, c), d = zt({ inputs: { x: l }, backend: e, attrs: { shape: u } }), h = cp({ inputs: { a: o, b: d }, backend: e }), p = Xx({ inputs: { x: h }, backend: e }), f = Yi({ inputs: { x: p }, backend: e, attrs: { axis: c, keepDims: !1 } }), m = zt({ inputs: { x: f }, backend: e, attrs: { shape: u } }), g = up({ inputs: { a: p, b: m }, backend: e }); return e.disposeIntermediateTensorInfo(l), e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), e.disposeIntermediateTensorInfo(m), g } const yD = { kernelName: dc, backendName: "cpu", kernelFunc: Vy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ID(n) { const { inputs: t, backend: e, attrs: s } = n, { logits: o } = t, { numSamples: r, seed: i, normalized: a } = s; it(o, "multinomial"); const c = a ? o : Vy({ inputs: { logits: o }, backend: e, attrs: { dim: -1 } }), l = c.shape[0], u = c.shape[1], d = e.data.get(c.dataId).values, h = [l, r], p = Se(Z(h), "int32"); for (let f = 0; f < l; ++f) { const m = f * u, g = new Float32Array(u - 1); g[0] = d[m]; for (let I = 1; I < g.length; ++I)g[I] = g[I - 1] + d[m + I]; const b = $d.alea(i.toString()), x = f * r; for (let I = 0; I < r; ++I) { const y = b(); p[x + I] = g.length; for (let C = 0; C < g.length; C++)if (y < g[C]) { p[x + I] = C; break } } } return a || e.disposeIntermediateTensorInfo(c), e.makeTensorInfo(h, "int32", p) } const CD = { kernelName: bf, backendName: "cpu", kernelFunc: ID };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const wD = Ad; function vD(n) { const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c } = s; it(o, "NonMaxSuppression"); const l = e.data.get(o.dataId).values, u = e.data.get(r.dataId).values, { selectedIndices: d } = wD(l, u, i, a, c); return e.makeTensorInfo([d.length], "int32", new Int32Array(d)) } const SD = { kernelName: ku, backendName: "cpu", kernelFunc: vD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kD = Od; function TD(n) { const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c, padToMaxOutputSize: l } = s; it(o, "NonMaxSuppressionPadded"); const u = e.data.get(o.dataId).values, d = e.data.get(r.dataId).values, { selectedIndices: h, validOutputs: p } = kD(u, d, i, a, c, l); return [e.makeTensorInfo([h.length], "int32", new Int32Array(h)), e.makeTensorInfo([], "int32", new Int32Array([p]))] } const ND = { kernelName: Tu, backendName: "cpu", kernelFunc: TD };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const RD = Pd; function $D(n) { const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c, softNmsSigma: l } = s; it(o, "NonMaxSuppressionWithScore"); const u = e.data.get(o.dataId).values, d = e.data.get(r.dataId).values, h = i, p = a, f = c, m = l, { selectedIndices: g, selectedScores: b } = RD(u, d, h, p, f, m); return [e.makeTensorInfo([g.length], "int32", new Int32Array(g)), e.makeTensorInfo([b.length], "float32", new Float32Array(b))] } const GD = { kernelName: Nu, backendName: "cpu", kernelFunc: $D };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function LD(n) { const { inputs: t, backend: e, attrs: s } = n, { indices: o } = t, { dtype: r, depth: i, onValue: a, offValue: c } = s; it(o, "oneHot"); const l = Z(o.shape), u = new Float32Array(l * i); u.fill(c); const d = e.data.get(o.dataId).values; for (let h = 0; h < l; ++h)d[h] >= 0 && d[h] < i && (u[h * i + d[h]] = a); return e.makeTensorInfo([...o.shape, i], r, u) } const ED = { kernelName: Ja, backendName: "cpu", kernelFunc: LD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fl(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (s.dtype === "string") throw new Error("zerosLike is not supported for string tensors"); if (s.dtype === "complex64") { const o = bo({ inputs: { input: s }, backend: e }), r = fl({ inputs: { x: o }, backend: e }), i = nr({ inputs: { input: s }, backend: e }), a = fl({ inputs: { x: i }, backend: e }), c = Ue({ inputs: { real: r, imag: a }, backend: e }); return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(r), e.disposeIntermediateTensorInfo(i), e.disposeIntermediateTensorInfo(a), c } else return pp({ backend: e, attrs: { shape: s.shape, value: 0, dtype: s.dtype } }) } const DD = { kernelName: fc, backendName: "cpu", kernelFunc: fl };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function zy(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (s.dtype === "string") throw new Error("onesLike is not supported for string tensors"); if (s.dtype === "complex64") { const o = bo({ inputs: { input: s }, backend: e }), r = zy({ inputs: { x: o }, backend: e }), i = nr({ inputs: { input: s }, backend: e }), a = fl({ inputs: { x: i }, backend: e }), c = Ue({ inputs: { real: r, imag: a }, backend: e }); return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(r), e.disposeIntermediateTensorInfo(i), e.disposeIntermediateTensorInfo(a), c } else return pp({ backend: e, attrs: { shape: s.shape, value: 1, dtype: s.dtype } }) } const WD = { kernelName: Qa, backendName: "cpu", kernelFunc: zy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Xy(n) { const { inputs: t, backend: e, attrs: s } = n, { axis: o } = s; if (t.length === 1) return pl({ inputs: { input: t[0] }, backend: e, attrs: { dim: o } }); const r = t[0].shape, i = t[0].dtype; t.forEach(u => { Pl(r, u.shape, "All tensors passed to stack must have matching shapes"), v(i === u.dtype, () => "All tensors passed to stack must have matching dtypes") }); const a = [], c = t.map(u => { const d = pl({ inputs: { input: u }, backend: e, attrs: { dim: o } }); return a.push(d), d }), l = sr({ inputs: c, backend: e, attrs: { axis: o } }); return a.forEach(u => e.disposeIntermediateTensorInfo(u)), l } const MD = { kernelName: ja, backendName: "cpu", kernelFunc: Xy };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function FD(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { paddings: r, constantValue: i } = s; it(o, "pad"); const a = r.map((x, I) => x[0] + o.shape[I] + x[1]), c = r.map(x => x[0]), l = e.data.get(o.dataId).values, u = Z(o.shape), d = o.shape.length, h = ct(o.shape), p = Z(a), f = a.length, m = ct(a), g = xe(o.dtype, p); i !== 0 && g.fill(i); for (let x = 0; x < u; x++) { const y = Go(x, d, h).map((w, k) => w + c[k]), C = Vn(y, f, m); g[C] = l[x] } return { dataId: e.write(g, a, o.dtype), shape: a, dtype: o.dtype } } const Ay = { kernelName: qa, backendName: "cpu", kernelFunc: FD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const VD = ae((n, t) => Math.pow(n, t)), zD = be(Yr, VD), XD = { kernelName: Yr, backendName: "cpu", kernelFunc: zD };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function AD(n) { const { inputs: t, backend: e, attrs: s } = n, { paramsNestedSplits: o, paramsDenseValues: r, indices: i } = t, a = o.map(g => e.data.get(g.dataId).values), c = o.map(g => g.shape), l = e.data.get(r.dataId).values, u = e.data.get(i.dataId).values, [d, h, p] = sy(a, c, l, r.shape, r.dtype, u, i.shape), f = d.map(g => e.makeTensorInfo([g.length], "int32", g)), m = e.makeTensorInfo(p, r.dtype, h); return f.concat([m]) } const OD = { kernelName: xf, backendName: "cpu", kernelFunc: AD };/**
 * @license
 * Copyright 2022 Google LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function PD(n) { const { inputs: t, backend: e } = n, { starts: s, limits: o, deltas: r } = t, i = e.data.get(s.dataId).values, a = e.data.get(o.dataId).values, c = e.data.get(r.dataId).values, [l, u] = ry(i, s.shape, s.dtype, a, o.shape, c, r.shape), d = e.makeTensorInfo([l.length], "int32", l), h = e.makeTensorInfo([u.length], s.dtype, u); return [d, h] } const KD = { kernelName: yf, backendName: "cpu", kernelFunc: PD };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ZD(n) { const { inputs: t, backend: e, attrs: s } = n, { shape: o, values: r, defaultValue: i, rowPartitionTensors: a } = t, { rowPartitionTypes: c } = s, l = e.data.get(o.dataId).values, u = e.data.get(r.dataId).values, d = e.data.get(i.dataId).values, h = a.map(g => e.data.get(g.dataId).values), p = a.map(g => g.shape), [f, m] = cy(l, o.shape, u, r.shape, r.dtype, d, i.shape, h, p, c); return e.makeTensorInfo(f, r.dtype, m) } const BD = { kernelName: If, backendName: "cpu", kernelFunc: ZD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function HD(n) { const { backend: t, attrs: e } = n, { start: s, stop: o, dtype: r, step: i } = e, a = ly(s, o, i, r); return t.makeTensorInfo([a.length], r, a) } const _D = { kernelName: Ru, backendName: "cpu", kernelFunc: HD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const UD = Lt(Qr, n => 1 / n), YD = { kernelName: Qr, backendName: "cpu", kernelFunc: UD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QD(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o } = t, { alignCorners: r, halfPixelCenters: i, size: a } = s; it(o, "resizeBilinear"); const c = ct(o.shape), [l, u] = a, [d, h, p, f] = o.shape, m = e.data.get(o.dataId).values, g = new Float32Array(Z([d, l, u, f])), b = [r && l > 1 ? h - 1 : h, r && u > 1 ? p - 1 : p], x = [r && l > 1 ? l - 1 : l, r && u > 1 ? u - 1 : u]; let I = 0; const y = b[0] / x[0], C = b[1] / x[1]; for (let w = 0; w < d; w++)for (let k = 0; k < l; k++) { let S; i ? S = y * (k + .5) - .5 : S = y * k; const T = Math.max(0, Math.floor(S)), R = S - T, G = Math.min(h - 1, Math.ceil(S)), F = w * c[0] + T * c[1], V = w * c[0] + G * c[1]; for (let z = 0; z < u; z++) { let X; i ? X = C * (z + .5) - .5 : X = C * z; const O = Math.max(0, Math.floor(X)), B = X - O, K = Math.min(p - 1, Math.ceil(X)), H = F + O * c[2], U = V + O * c[2], Y = F + K * c[2], j = V + K * c[2]; for (let J = 0; J < f; J++) { const nt = m[H + J], q = m[U + J], rt = m[Y + J], lt = m[j + J], pt = nt + (rt - nt) * B, ht = q + (lt - q) * B, xt = pt + (ht - pt) * R; g[I++] = xt } } } return e.makeTensorInfo([d, l, u, f], "float32", g) } const JD = { kernelName: oc, backendName: "cpu", kernelFunc: QD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jD(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o, dy: r } = t, { alignCorners: i } = s; it([r, o], "resizeBilinearGrad"); const a = ct(o.shape), [c, l, u, d] = o.shape, [, h, p] = r.shape, f = new Float32Array(c * l * u * d), m = [i && h > 1 ? l - 1 : l, i && p > 1 ? u - 1 : u], g = [i && h > 1 ? h - 1 : h, i && p > 1 ? p - 1 : p], b = m[0] / g[0], x = m[1] / g[1], I = e.data.get(r.dataId).values; let y = 0; for (let C = 0; C < c; C++) { const w = C * a[0]; for (let k = 0; k < h; k++) { const S = k * b, T = Math.floor(S), R = Math.min(Math.ceil(S), l - 1), G = w + T * a[1], F = w + R * a[1], V = S - T, z = 1 - V; for (let X = 0; X < p; X++) { const O = X * x, B = Math.floor(O), K = Math.min(Math.ceil(O), u - 1), H = O - B, U = 1 - H, Y = G + B * a[2], j = G + K * a[2], J = F + B * a[2], nt = F + K * a[2], q = z * U, rt = z * H, lt = V * U, pt = V * H; for (let ht = 0; ht < d; ht++) { const xt = I[y++]; f[Y + ht] += xt * q, f[j + ht] += xt * rt, f[J + ht] += xt * lt, f[nt + ht] += xt * pt } } } } return e.makeTensorInfo([c, u, l, d], "float32", f) } const qD = { kernelName: Lu, backendName: "cpu", kernelFunc: jD };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tW(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o } = t, { alignCorners: r, halfPixelCenters: i, size: a } = s; it(o, "resizeNearestNeighbor"); const c = ct(o.shape), [l, u] = a, [d, h, p, f] = o.shape, m = e.data.get(o.dataId).values, g = new Float32Array(d * l * u * f), b = [r && l > 1 ? h - 1 : h, r && u > 1 ? p - 1 : p], x = [r && l > 1 ? l - 1 : l, r && u > 1 ? u - 1 : u], I = b[0] / x[0], y = b[1] / x[1]; let C = 0; for (let w = 0; w < d; w++) { const k = w * c[0]; for (let S = 0; S < l; S++) { const T = i ? I * (S + .5) : I * S; let R = Math.min(h - 1, r ? Math.round(T) : Math.floor(T)); i && (R = Math.max(0, R)); const G = k + R * c[1]; for (let F = 0; F < u; F++) { const V = i ? y * (F + .5) : y * F; let z = Math.min(p - 1, r ? Math.round(V) : Math.floor(V)); i && (z = Math.max(0, z)); const X = G + z * c[2]; for (let O = 0; O < f; O++) { const B = m[X + O]; g[C++] = B } } } } return e.makeTensorInfo([d, l, u, f], o.dtype, g) } const eW = { kernelName: sc, backendName: "cpu", kernelFunc: tW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nW(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o, dy: r } = t, { alignCorners: i } = s; it([r, o], "resizeNearestNeighborGrad"); const a = ct(o.shape), c = ct(r.shape), [l, u, d, h] = o.shape, [, p, f] = r.shape, m = new Float32Array(l * u * d * h), g = e.data.get(r.dataId).values, b = [i && p > 1 ? u - 1 : u, i && f > 1 ? d - 1 : d], x = [i && p > 1 ? p - 1 : p, i && f > 1 ? f - 1 : f], I = b[0] / x[0], y = b[1] / x[1], C = 1 / I, w = 1 / y, k = Math.ceil(C) * 2 + 2, S = Math.ceil(w) * 2 + 2; for (let T = 0; T < l; T++) { const R = T * a[0]; for (let G = 0; G < u; G++) { const F = R + G * a[1], V = Math.floor(G * C), z = Math.floor(V - k / 2); for (let X = 0; X < d; X++) { const O = F + X * a[2], B = Math.floor(X * w), K = Math.floor(B - S / 2); for (let H = 0; H < h; H++) { let U = 0; for (let Y = 0; Y < k; Y++) { const j = Y + z; if (j < 0 || j >= p) continue; const J = R + j * c[1], nt = j * I, q = Math.min(u - 1, i ? Math.round(nt) : Math.floor(nt)); if (G === q) for (let rt = 0; rt < S; rt++) { const lt = rt + K; if (lt < 0 || lt >= f) continue; const pt = J + lt * c[2], ht = lt * y, xt = Math.min(d - 1, i ? Math.round(ht) : Math.floor(ht)); X === xt && (U += g[pt + H]) } } m[O + H] = U } } } } return e.makeTensorInfo(o.shape, o.dtype, m) } const sW = { kernelName: Gu, backendName: "cpu", kernelFunc: nW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function oW(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { dims: r } = s; it(o, "reverse"); const i = o.shape.length, a = It(r, o.shape); if (i === 0) return Un({ inputs: { x: o }, backend: e }); const c = new ke(o.shape, o.dtype), l = e.bufferSync(o); for (let u = 0; u < c.size; u++) { const d = c.indexToLoc(u), h = d.slice(); a.forEach(p => h[p] = o.shape[p] - 1 - h[p]), c.set(l.get(...h), ...d) } return e.makeTensorInfo(c.shape, c.dtype, c.values) } const rW = { kernelName: rc, backendName: "cpu", kernelFunc: oW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iW = { kernelName: zu, backendName: "cpu", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { image: s } = n, { radians: o, fillValue: r, center: i } = t, a = e, c = xe(s.dtype, Z(s.shape)), [l, u, d, h] = s.shape, [p, f] = th(i, u, d), m = 255, g = Math.sin(o), b = Math.cos(o), x = a.data.get(s.dataId).values; for (let y = 0; y < l; y++) { const C = y * d * u * h; for (let w = 0; w < u; w++) { const k = w * (d * h); for (let S = 0; S < d; S++) { const T = S * h; for (let R = 0; R < h; R++) { const G = [l, w, S, R], F = G[2], V = G[1]; let z = (F - p) * b - (V - f) * g, X = (F - p) * g + (V - f) * b; z = Math.round(z + p), X = Math.round(X + f); let O = r; if (typeof r != "number" && (R === 3 ? O = m : O = r[R]), z >= 0 && z < d && X >= 0 && X < u) { const K = X * (d * h), H = z * h, U = C + K + H + R; O = x[U] } const B = C + k + T + R; c[B] = O } } } } return { dataId: a.write(c, s.shape, s.dtype), shape: s.shape, dtype: s.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aW = Lt(qr, n => { const t = Math.floor(n); return n - t < .5 ? Math.floor(n) : n - t > .5 ? Math.ceil(n) : t % 2 === 0 ? t : t + 1 }), cW = { kernelName: qr, backendName: "cpu", kernelFunc: aW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lW(n) { const { inputs: t, backend: e, attrs: s } = n, { indices: o, updates: r } = t, { shape: i } = s, { sliceRank: a, numUpdates: c, sliceSize: l, strides: u, outputSize: d } = Ri(r, o, i), h = !0, p = e.bufferSync(o), f = e.bufferSync(r), m = er(p, f, i, d, l, c, a, u, 0, h); return e.makeTensorInfo(i, m.dtype, m.values) } const uW = { kernelName: Cf, backendName: "cpu", kernelFunc: lW };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dW(n, t) { let e = 0, s = n.length, o = 0; for (; e < s;)o = Math.floor((e + s) / 2), n[o] < t ? e = o + 1 : s = o; return s } function hW(n, t) { let e = 0, s = n.length, o = 0; for (; e < s;)o = Math.floor((e + s) / 2), n[o] <= t ? e = o + 1 : s = o; return s } function pW(n, t, e, s, o, r) { const i = ne("int32", e * o); for (let a = 0; a < e; ++a) { const c = n.slice(a * s, (a + 1) * s), l = a * o; for (let u = 0; u < o; ++u)i[l + u] = r === "left" ? dW(c, t[u + l]) : hW(c, t[u + l]) } return i }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function fW(n) { const { inputs: t, backend: e, attrs: s } = n, { sortedSequence: o, values: r } = t, { side: i } = s, a = e.data.get(o.dataId).values, c = e.data.get(r.dataId).values, l = pW(a, c, o.shape[0], o.shape[1], r.shape[1], i); return e.makeTensorInfo(r.shape, "int32", l) } const mW = { kernelName: wf, backendName: "cpu", kernelFunc: fW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function gW(n) { const { inputs: t, backend: e } = n, { condition: s, t: o, e: r } = t; it([s, o, r], "select"); const i = s.shape.length, a = e.data.get(s.dataId).values, c = e.data.get(o.dataId).values, l = e.data.get(r.dataId).values, u = Ze(o.dtype, r.dtype), d = Se(Z(o.shape), u); let h = 0; const p = i === 0 || i > 1 || o.shape.length === 1 ? 1 : Z(o.shape.slice(1)); for (let f = 0; f < a.length; f++)for (let m = 0; m < p; m++)a[f] === 1 ? d[h++] = c[f] : d[h++] = l[f]; return e.makeTensorInfo(o.shape, u, d) } const bW = { kernelName: ic, backendName: "cpu", kernelFunc: gW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const xW = Vc, yW = zc, IW = Lt(ei, n => n >= 0 ? yW * n : xW * (Math.exp(n) - 1)), CW = { kernelName: ei, backendName: "cpu", kernelFunc: IW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const wW = Lt(oi, n => n < 0 ? -1 : n > 0 ? 1 : 0), vW = { kernelName: oi, backendName: "cpu", kernelFunc: wW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const SW = Lt(ni, n => Math.sin(n)), kW = { kernelName: ni, backendName: "cpu", kernelFunc: SW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const TW = Lt(si, n => Math.sinh(n)), NW = { kernelName: si, backendName: "cpu", kernelFunc: TW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Oy = Math.log(11920928955078125e-23) + 2, RW = Lt(ii, n => { const t = n > -Oy, e = n < Oy, s = Math.exp(n); let o; return e ? o = s : t ? o = n : o = Math.log(1 + s), o }), $W = { kernelName: ii, backendName: "cpu", kernelFunc: RW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function GW(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockShape: r, paddings: i } = s; it([o], "spaceToBatchND"); const a = Z(r), c = [[0, 0]]; c.push(...i); for (let w = 1 + r.length; w < o.shape.length; ++w)c.push([0, 0]); const l = Ay.kernelFunc({ inputs: { x: o }, backend: e, attrs: { paddings: c, constantValue: 0 } }), u = $i(l.shape, r, a, !1), d = Gi(u.length, r.length, !1), h = Li(l.shape, r, a, !1), m = zt({ inputs: { x: l }, backend: e, attrs: { shape: u } }), x = Ae({ inputs: { x: m }, backend: e, attrs: { perm: d } }), C = zt({ inputs: { x }, backend: e, attrs: { shape: h } }); return e.disposeIntermediateTensorInfo(l), e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(x), C } const LW = { kernelName: lc, backendName: "cpu", kernelFunc: GW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function EW(n) {
        const { inputs: t, backend: e } = n, { indices: s, values: o, denseShape: r, defaultValue: i } = t; if (r.shape.length !== 1) throw new Error(`Dense shape must be a vector, saw:
        ${r.shape}`); if (s.shape.length !== 2) throw new Error(`Indices must be a matrix, saw:
        ${s.shape}`); if (o.shape.length !== 1) throw new Error(`Values must be a vector, saw:
        ${o.shape}`); if (i.shape.length !== 0) throw new Error(`Default value must be a scalar, saw:
        ${i.shape}`); const a = e.data.get(s.dataId).values, c = e.data.get(o.dataId).values, l = e.data.get(r.dataId).values, u = e.data.get(i.dataId).values[0], [d, h, p, f, m] = py(a, s.shape, s.dtype, c, o.dtype, l, u); return [e.makeTensorInfo(h, s.dtype, d), e.makeTensorInfo([h[0]], o.dtype, p), e.makeTensorInfo([f.length], "bool", new Uint8Array(f.map(g => Number(g)))), e.makeTensorInfo([m.length], s.dtype, new Int32Array(m))]
    } const DW = { kernelName: vf, backendName: "cpu", kernelFunc: EW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function WW(n) {
        const { inputs: t, backend: e } = n, { inputIndices: s, inputShape: o, newShape: r } = t; if (s.shape.length !== 2) throw new Error(`Input indices should be a matrix but received shape
        ${s.shape}`); if (o.shape.length !== 1) throw new Error(`Input shape should be a vector but received shape
        ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Target shape should be a vector but received shape ${r.shape}`); const i = Array.from(e.data.get(o.dataId).values), a = e.data.get(s.dataId).values, c = Array.from(e.data.get(r.dataId).values), [l, u, d] = fy(a, s.shape, s.dtype, i, c); return [e.makeTensorInfo(u, s.dtype, l), e.makeTensorInfo([d.length], r.dtype, new Int32Array(d))]
    } const MW = { kernelName: Sf, backendName: "cpu", kernelFunc: WW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function FW(n) {
        const { inputs: t, backend: e } = n, { data: s, indices: o, segmentIds: r } = t; if (s.shape.length < 1) throw new Error("Data should be at least 1 dimensional but received scalar"); if (o.shape.length !== 1) throw new Error(`Indices should be a vector but received shape
          ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Segment ids should be a vector but received shape
          ${r.shape}`); if (o.shape[0] !== r.shape[0]) throw new Error("segmentIds and indices should have same size."); const i = e.data.get(s.dataId).values, a = e.data.get(o.dataId).values, c = e.data.get(r.dataId).values, [l, u] = ap(i, s.shape, s.dtype, a, c, !0); return e.makeTensorInfo(u, s.dtype, l)
    } const VW = { kernelName: kf, backendName: "cpu", kernelFunc: FW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function zW(n) {
        const { inputs: t, backend: e } = n, { data: s, indices: o, segmentIds: r } = t; if (s.shape.length < 1) throw new Error("Data should be at least 1 dimensional but received scalar"); if (o.shape.length !== 1) throw new Error(`Indices should be a vector but received shape
         ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Segment ids should be a vector but received shape
         ${r.shape}`); if (o.shape[0] !== r.shape[0]) throw new Error("segmentIds and indices should have same size."); const i = e.data.get(s.dataId).values, a = e.data.get(o.dataId).values, c = e.data.get(r.dataId).values, [l, u] = ap(i, s.shape, s.dtype, a, c); return e.makeTensorInfo(u, s.dtype, l)
    } const XW = { kernelName: Tf, backendName: "cpu", kernelFunc: zW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function AW(n) { const { inputs: t, backend: e, attrs: s } = n, { sparseIndices: o, sparseValues: r, defaultValue: i } = t, { outputShape: a } = s, { sliceRank: c, numUpdates: l, sliceSize: u, strides: d, outputSize: h } = Ri(r, o, a), p = !1, f = e.bufferSync(o); let m; switch (r.dtype) { case "bool": { const g = e.bufferSync(r), b = !!e.data.get(i.dataId).values[0]; m = er(f, g, a, h, u, l, c, d, b, p); break } case "float32": { const g = e.bufferSync(r), b = e.data.get(i.dataId).values[0]; m = er(f, g, a, h, u, l, c, d, b, p); break } case "int32": { const g = e.bufferSync(r), b = e.data.get(i.dataId).values[0]; m = er(f, g, a, h, u, l, c, d, b, p); break } case "string": { const g = e.bufferSync(r), b = ms(e.data.get(i.dataId).values[0]); m = er(f, g, a, h, u, l, c, d, b, p); break } default: throw new Error(`Unsupported type ${r.dtype}`) }return e.makeTensorInfo(a, m.dtype, m.values) } const OW = { kernelName: Nf, backendName: "cpu", kernelFunc: AW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function PW(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { numOrSizeSplits: r, axis: i } = s, a = It(i, o.shape)[0], c = gh(o, r, a), l = new Array(o.shape.length).fill(0), u = o.shape.slice(); return c.map(d => { const h = [...u]; h[a] = d; const p = xo({ inputs: { x: o }, backend: e, attrs: { begin: l, size: h } }); return l[a] += d, p }) } const KW = { kernelName: uc, backendName: "cpu", kernelFunc: PW };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ZW = { kernelName: Eu, backendName: "cpu", kernelFunc: ({ inputs: n, backend: t }) => { const { x: e } = n, s = t; it(e, "square"); const o = s.data.get(e.dataId).values, r = new Float32Array(o.length); for (let a = 0; a < o.length; ++a) { const c = o[a]; r[a] = c * c } return { dataId: s.write(r, e.shape, e.dtype), shape: e.shape, dtype: e.dtype } } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const BW = Lt(pi, (n, t) => { const e = t; return isNaN(n) ? NaN : n > 0 ? 1 : e.alpha }), HW = { kernelName: pi, backendName: "cpu", kernelFunc: BW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _W(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { begin: r, end: i, strides: a, beginMask: c, endMask: l, ellipsisMask: u, newAxisMask: d, shrinkAxisMask: h } = s; it(o, "stridedSlice"); const { finalShapeSparse: p, finalShape: f, isIdentity: m, sliceDim0: g, isSimpleSlice: b, begin: x, end: I, strides: y } = Jd(o.shape, r, i, a, c, l, u, d, h); let C; if (m) C = zt({ inputs: { x: o }, backend: e, attrs: { shape: f } }); else if (g || b) { v(o.shape.length >= 1, () => `Input must have rank at least 1, got: ${o.shape.length}`); const w = Ud(x, I, y), k = xo({ inputs: { x: o }, backend: e, attrs: { begin: x, size: w } }); C = zt({ inputs: { x: k }, backend: e, attrs: { shape: f } }), e.disposeIntermediateTensorInfo(k) } else { const w = e.bufferSync(o), k = gy(p, w, y, x); C = e.makeTensorInfo(f, k.dtype, k.values) } return C } const UW = { kernelName: Du, backendName: "cpu", kernelFunc: _W };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function YW(n) { const { inputs: t, backend: e, attrs: s } = n, { separator: o, nGramWidths: r, leftPad: i, rightPad: a, padWidth: c, preserveShortSequences: l } = s, { data: u, dataSplits: d } = t, h = e.data.get(u.dataId).values, p = e.data.get(d.dataId).values, [f, m] = by(h, p, o, r, i, a, c, l); return [e.makeTensorInfo([f.length], "string", f), e.makeTensorInfo(d.shape, "int32", m)] } const QW = { kernelName: Rf, backendName: "cpu", kernelFunc: YW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JW(n) { const { inputs: t, backend: e, attrs: s } = n, { skipEmpty: o } = s, { input: r, delimiter: i } = t; if (r.dtype !== "string") throw new Error("Input must be of datatype string"); if (r.shape.length !== 1) throw new Error(`Input must be a vector, got shape: ${r.shape}`); if (i.shape.length !== 0) throw new Error(`Delimiter must be a scalar, got shape: ${i.shape}`); const a = e.data.get(r.dataId).values, c = e.data.get(i.dataId).values[0], [l, u, d] = xy(a, c, o), h = u.length; return [e.makeTensorInfo([h, 2], "int32", l), e.makeTensorInfo([h], "string", u), e.makeTensorInfo([2], "int32", new Int32Array(d))] } const jW = { kernelName: $f, backendName: "cpu", kernelFunc: JW };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qW(n) { const { inputs: t, backend: e, attrs: s } = n, { numBuckets: o } = s, { input: r } = t; if (r.dtype !== "string") throw new Error("Input must be of datatype string"); if (o <= 0) throw new Error("Number of buckets must be at least 1"); const i = e.data.get(r.dataId).values, a = yy(i, o); return e.makeTensorInfo(r.shape, "int32", a) } const tM = { kernelName: Gf, backendName: "cpu", kernelFunc: qW };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const eM = Lt(ui, n => Math.tan(n)), nM = { kernelName: ui, backendName: "cpu", kernelFunc: eM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const sM = Lt(di, n => Math.tanh(n)), oM = { kernelName: di, backendName: "cpu", kernelFunc: sM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rM(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { reps: r } = s; it(o, "tile"); const i = Cy(e.bufferSync(o), r); return e.makeTensorInfo(i.shape, i.dtype, i.values) } const iM = { kernelName: hi, backendName: "cpu", kernelFunc: rM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aM(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { k: r, sorted: i } = s; it(o, "topk"); const a = e.data.get(o.dataId).values, [c, l] = vy(a, o.shape, o.dtype, r, i); return [e.makeTensorInfo(c.shape, c.dtype, c.values), e.makeTensorInfo(l.shape, l.dtype, l.values)] } const cM = { kernelName: Wu, backendName: "cpu", kernelFunc: aM };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lM(n) { const { inputs: t, attrs: e, backend: s } = n, { image: o, transforms: r } = t, { interpolation: i, fillMode: a, fillValue: c, outputShape: l } = e, [u, d, h, p] = o.shape, [f, m] = l ?? [d, h], g = [u, f, m, p], b = ct(o.shape), x = b[0], I = b[1], y = b[2], C = ct(g), w = C[0], k = C[1], S = C[2], T = xe(o.dtype, Z(g)); T.fill(c); const R = s.data.get(o.dataId).values, G = s.data.get(r.dataId).values; for (let V = 0; V < u; ++V) { const z = r.shape[0] === 1 ? G : G.subarray(V * 8, V * 8 + 8); for (let X = 0; X < f; ++X)for (let O = 0; O < m; ++O)for (let B = 0; B < p; ++B) { let K; const H = z[6] * O + z[7] * X + 1; if (H === 0) continue; const U = (z[0] * O + z[1] * X + z[2]) / H, Y = (z[3] * O + z[4] * X + z[5]) / H, j = Py(U, h, a), J = Py(Y, d, a); switch (i) { case "nearest": K = mM(R, d, h, x, I, y, V, J, j, B, c); break; case "bilinear": K = gM(R, d, h, x, I, y, V, J, j, B, c); break; default: throw new Error(`Error in Transform: Expect 'nearest' or 'bilinear', but got ${i}`) }const nt = V * w + X * k + O * S + B; T[nt] = K } return s.makeTensorInfo(g, o.dtype, T) } return { dataId: s.write(T, g, o.dtype), shape: o.shape, dtype: o.dtype } } const uM = { kernelName: Mu, backendName: "cpu", kernelFunc: lM }; function Py(n, t, e) { switch (e) { case "reflect": return dM(n, t); case "wrap": return hM(n, t); case "nearest": return fM(n, t); case "constant": default: return pM(n) } } function dM(n, t) { let e = n; if (e < 0) if (t <= 1) e = 0; else { const s = 2 * t; e < s && (e = s * Math.trunc(-e / s) + e), e = e < -t ? e + s : -e - 1 } else if (e > t - 1) if (t <= 1) e = 0; else { const s = 2 * t; e -= s * Math.trunc(e / s), e >= t && (e = s - e - 1) } return Xs(0, e, t - 1) } function hM(n, t) { let e = n; if (e < 0) if (t <= 1) e = 0; else { const s = t - 1; e += t * (Math.trunc(-e / s) + 1) } else if (e > t - 1) if (t <= 1) e = 0; else { const s = t - 1; e -= t * Math.trunc(e / s) } return Xs(0, e, t - 1) } function pM(n, t) { return n } function fM(n, t) { return Xs(0, n, t - 1) } function Qi(n, t, e, s, o, r, i, a, c, l, u) { const d = i * s + a * o + c * r + l; return 0 <= a && a < t && 0 <= c && c < e ? n[d] : u } function mM(n, t, e, s, o, r, i, a, c, l, u) { const d = Math.round(a), h = Math.round(c); return Qi(n, t, e, s, o, r, i, d, h, l, u) } function gM(n, t, e, s, o, r, i, a, c, l, u) { const d = Math.floor(a), h = Math.floor(c), p = d + 1, f = h + 1, m = (f - c) * Qi(n, t, e, s, o, r, i, d, h, l, u) + (c - h) * Qi(n, t, e, s, o, r, i, d, f, l, u), g = (f - c) * Qi(n, t, e, s, o, r, i, p, h, l, u) + (c - h) * Qi(n, t, e, s, o, r, i, p, f, l, u); return (p - a) * m + (a - d) * g }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bM(n) { const { inputs: t, attrs: e, backend: s } = n, { axis: o } = e, { x: r } = t; it(r, "unique"); const i = s.data.get(r.dataId).values, { outputValues: a, outputShape: c, indices: l } = Sy(i, o, r.shape, r.dtype); return [s.makeTensorInfo(c, r.dtype, a), s.makeTensorInfo([l.length], "int32", l)] } const xM = { kernelName: Fu, backendName: "cpu", kernelFunc: bM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function yM(n) { const { inputs: t, backend: e, attrs: s } = n, { value: o } = t; let { axis: r } = s; r < 0 && (r += o.shape.length); const i = o.shape.length, a = o.shape[r], c = new Array(i - 1); let l = 0; for (let p = 0; p < i; p++)p !== r && (c[l++] = o.shape[p]); const u = new Array(i).fill(0), d = o.shape.slice(); d[r] = 1; const h = new Array(a); for (let p = 0; p < h.length; p++) { u[r] = p; const f = xo({ inputs: { x: o }, backend: e, attrs: { begin: u, size: d } }); h[p] = zt({ inputs: { x: f }, backend: e, attrs: { shape: c } }), e.disposeIntermediateTensorInfo(f) } return h } const IM = { kernelName: hc, backendName: "cpu", kernelFunc: yM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function CM(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, segmentIds: r } = t, { numSegments: i } = s; it(o, "unsortedSegmentSum"); const a = o.shape.length, c = r.shape.length, l = [], u = [], d = a - c; let h = r; for (let f = 0; f < d; ++f) { const m = pl({ inputs: { input: h }, backend: e, attrs: { dim: f + 1 } }); h = m, u.push(m) } for (let f = 0; f < i; ++f) { const m = ps(f, "int32"), g = e.makeTensorInfo([], "int32", m), b = Vx({ inputs: { a: g, b: h }, backend: e }), x = Gs({ inputs: { x: b }, backend: e, attrs: { dtype: "float32" } }), I = ul({ inputs: { a: x, b: o }, backend: e }), y = Yi({ inputs: { x: I }, backend: e, attrs: { axis: 0, keepDims: !1 } }); l.push(y), u.push(g), u.push(b), u.push(x), u.push(I), u.push(y) } const p = Xy({ inputs: l, backend: e, attrs: { axis: 0 } }); return u.forEach(f => e.disposeIntermediateTensorInfo(f)), p } const wM = { kernelName: pc, backendName: "cpu", kernelFunc: CM };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const vM = [IL, iG, wL, SL, hG, TL, RL, GL, EL, WL, FL, zL, AL, KL, BL, UL, QL, jL, tE, xL, nE, oE, iE, cE, uG, fG, uE, aG, dE, pE, fE, gE, xE, IE, wE, SE, TE, RE, GE, EE, WE, FE, zE, XE, OE, KE, BE, HE, _E, UE, JE, dL, qE, mG, a3, gG, c3, xG, f3, m3, b3, IG, I3, w3, S3, T3, R3, wG, SG, cG, G3, hE, E3, W3, F3, hL, TG, RG, z3, GG, A3, K3, B3, U3, Q3, j3, q3, EG, eD, sD, rD, aD, lD, dD, pD, WG, mD, xD, CD, FG, zG, SD, ND, GD, AG, ED, WD, MD, Ay, XD, fL, KG, OD, KD, BD, _D, lG, dp, YD, mL, gL, bL, JD, qD, eW, sW, rW, iW, cW, JG, uW, mW, bW, CW, qG, vW, kW, NW, tL, yD, $W, LW, DW, MW, VW, XW, OW, KW, sL, ZW, rL, HW, UW, QW, jW, tM, lL, YE, nM, oM, iM, cM, uM, OG, xM, IM, wM, DD]; for (const n of vM) Je(n);/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const yo = {}, ml = { alpha: !1, antialias: !1, premultipliedAlpha: !1, preserveDrawingBuffer: !1, depth: !1, stencil: !1, failIfMajorPerformanceCaveat: !0 }; function SM(n, t) { yo[n] = t } function Mn(n, t) { if (!(n in yo) || t != null) { const s = TM(n, t); if (s !== null) yo[n] = s; else return console.log("Could not get context for WebGL version", n), null } const e = yo[n]; return e == null || e.isContextLost() ? (delete yo[n], Mn(n)) : (e.disable(e.DEPTH_TEST), e.disable(e.STENCIL_TEST), e.disable(e.BLEND), e.disable(e.DITHER), e.disable(e.POLYGON_OFFSET_FILL), e.disable(e.SAMPLE_COVERAGE), e.enable(e.SCISSOR_TEST), e.enable(e.CULL_FACE), e.cullFace(e.BACK), yo[n]) } function kM(n) { if (typeof OffscreenCanvas < "u" && n === 2) return new OffscreenCanvas(300, 150); if (typeof document < "u") return document.createElement("canvas"); throw new Error("Cannot create a canvas in this context") } function TM(n, t) { if (n !== 1 && n !== 2) throw new Error("Cannot get WebGL rendering context, WebGL is disabled."); const e = t ?? kM(n); return e.addEventListener("webglcontextlost", s => { s.preventDefault(), delete yo[n] }, !1), A().getBool("SOFTWARE_WEBGL_ENABLED") && (ml.failIfMajorPerformanceCaveat = !1), n === 1 ? e.getContext("webgl", ml) || e.getContext("experimental-webgl", ml) : e.getContext("webgl2", ml) }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */var Ji; (function (n) { n[n.DENSE = 0] = "DENSE", n[n.SHARED_BATCH = 1] = "SHARED_BATCH" })(Ji || (Ji = {})); var an; (function (n) { n[n.RENDER = 0] = "RENDER", n[n.UPLOAD = 1] = "UPLOAD", n[n.PIXELS = 2] = "PIXELS", n[n.DOWNLOAD = 3] = "DOWNLOAD" })(an || (an = {})); var Ce; (function (n) { n[n.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", n[n.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", n[n.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", n[n.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", n[n.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16" })(Ce || (Ce = {})); function ji(n, t) { return [t, n] } function NM(n, t) { return n * t } function gl(n) { const t = Z(n), e = Math.ceil(t / 4); return Zl(e) } function or(n, t) { return [Math.max(1, Math.ceil(t / 2)), Math.max(1, Math.ceil(n / 2))] } function RM(n, t) { const [e, s] = or(n, t); return e * s * 4 } function fp(n, t) { const e = n; let s, o, r, i, a, c, l, u, d, h; return A().getNumber("WEBGL_VERSION") === 2 ? (s = e.R32F, o = e.R16F, r = e.RGBA16F, i = e.RGBA32F, a = e.RED, l = 4, u = 1, d = e.HALF_FLOAT, h = e.FLOAT, c = e.RGBA8) : (s = n.RGBA, o = n.RGBA, r = n.RGBA, i = e.RGBA, a = n.RGBA, l = 4, u = 4, d = t != null ? t.HALF_FLOAT_OES : null, h = n.FLOAT, c = n.RGBA), { internalFormatFloat: s, internalFormatHalfFloat: o, internalFormatPackedHalfFloat: r, internalFormatPackedFloat: i, textureFormatFloat: a, downloadTextureFormat: c, downloadUnpackNumChannels: l, defaultNumChannels: u, textureTypeHalfFloat: d, textureTypeFloat: h } }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function st(n, t) { const e = t(); return A().getBool("DEBUG") && $M(n), e } function $M(n) { const t = n.getError(); if (t !== n.NO_ERROR) throw new Error("WebGL Error: " + DM(n, t)) } const GM = 596e-10, LM = 65504; function EM(n) { return !!(A().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || n === 0 || GM < Math.abs(n) && Math.abs(n) < LM) } function DM(n, t) { switch (t) { case n.NO_ERROR: return "NO_ERROR"; case n.INVALID_ENUM: return "INVALID_ENUM"; case n.INVALID_VALUE: return "INVALID_VALUE"; case n.INVALID_OPERATION: return "INVALID_OPERATION"; case n.INVALID_FRAMEBUFFER_OPERATION: return "INVALID_FRAMEBUFFER_OPERATION"; case n.OUT_OF_MEMORY: return "OUT_OF_MEMORY"; case n.CONTEXT_LOST_WEBGL: return "CONTEXT_LOST_WEBGL"; default: return `Unknown error code ${t}` } } function bl(n, t) { return cs(n, () => n.getExtension(t), 'Extension "' + t + '" not supported on this browser.') } function WM(n, t) { const e = cs(n, () => n.createShader(n.VERTEX_SHADER), "Unable to create vertex WebGLShader."); if (st(n, () => n.shaderSource(e, t)), st(n, () => n.compileShader(e)), n.getShaderParameter(e, n.COMPILE_STATUS) === !1) throw console.log(n.getShaderInfoLog(e)), new Error("Failed to compile vertex shader."); return e } function MM(n, t) { const e = cs(n, () => n.createShader(n.FRAGMENT_SHADER), "Unable to create fragment WebGLShader."); if (st(n, () => n.shaderSource(e, t)), st(n, () => n.compileShader(e)), A().get("ENGINE_COMPILE_ONLY")) return e; if (n.getShaderParameter(e, n.COMPILE_STATUS) === !1) throw Ky(t, n.getShaderInfoLog(e)), new Error("Failed to compile fragment shader."); return e } const FM = /ERROR: [0-9]+:([0-9]+):/g; function Ky(n, t) {
        const e = FM.exec(t); if (e == null) { console.log(`Couldn't parse line number in error: ${t}`), console.log(n); return } const s = +e[1], o = n.split(`
`), r = o.length.toString().length + 2, i = o.map((d, h) => $o((h + 1).toString(), r) + d); let a = 0; for (let d = 0; d < i.length; d++)a = Math.max(i[d].length, a); const c = i.slice(0, s - 1), l = i.slice(s - 1, s), u = i.slice(s); console.log(c.join(`
`)), console.log(t.split(`
`)[0]), console.log(`%c ${$o(l[0], a)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(u.join(`
`))
    } function VM(n) { return cs(n, () => n.createProgram(), "Unable to create WebGLProgram.") } function zM(n, t) { if (st(n, () => n.linkProgram(t)), !A().get("ENGINE_COMPILE_ONLY") && n.getProgramParameter(t, n.LINK_STATUS) === !1) throw console.log(n.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.") } function mp(n, t) { if (st(n, () => n.validateProgram(t)), n.getProgramParameter(t, n.VALIDATE_STATUS) === !1) throw console.log(n.getProgramInfoLog(t)), new Error("Shader program validation failed.") } function XM(n, t) { const e = cs(n, () => n.createBuffer(), "Unable to create WebGLBuffer"); return st(n, () => n.bindBuffer(n.ARRAY_BUFFER, e)), st(n, () => n.bufferData(n.ARRAY_BUFFER, t, n.STATIC_DRAW)), e } function AM(n, t) { const e = cs(n, () => n.createBuffer(), "Unable to create WebGLBuffer"); return st(n, () => n.bindBuffer(n.ELEMENT_ARRAY_BUFFER, e)), st(n, () => n.bufferData(n.ELEMENT_ARRAY_BUFFER, t, n.STATIC_DRAW)), e } function OM(n) { return cs(n, () => n.createTexture(), "Unable to create WebGLTexture.") } function PM(n, t) { const e = A().getNumber("WEBGL_MAX_TEXTURE_SIZE"); if (n <= 0 || t <= 0) { const s = `[${n}x${t}]`; throw new Error("Requested texture size " + s + " is invalid.") } if (n > e || t > e) { const s = `[${n}x${t}]`, o = `[${e}x${e}]`; throw new Error("Requested texture size " + s + " greater than WebGL maximum on this browser / GPU " + o + ".") } } function KM(n) { return cs(n, () => n.createFramebuffer(), "Unable to create WebGLFramebuffer.") } function Zy(n, t, e, s, o, r, i) { const a = n.getAttribLocation(t, e); return a === -1 ? !1 : (st(n, () => n.bindBuffer(n.ARRAY_BUFFER, s)), st(n, () => n.vertexAttribPointer(a, o, n.FLOAT, !1, r, i)), st(n, () => n.enableVertexAttribArray(a)), !0) } function ZM(n, t, e) { YM(n, e), st(n, () => n.activeTexture(n.TEXTURE0 + e)), st(n, () => n.bindTexture(n.TEXTURE_2D, t)) } function BM(n, t, e) { return cs(n, () => n.getUniformLocation(t, e), 'uniform "' + e + '" not present in program.') } function HM(n, t, e) { return n.getUniformLocation(t, e) } function _M(n, t, e, s) { st(n, () => ZM(n, t, s)), st(n, () => n.uniform1i(e, s)) } function gp(n, t, e) { st(n, () => n.bindFramebuffer(n.FRAMEBUFFER, e)), st(n, () => n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, t, 0)) } function By(n, t) { st(n, () => n.bindFramebuffer(n.FRAMEBUFFER, t)), st(n, () => n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, null, 0)) } function xl(n) { const t = n.checkFramebufferStatus(n.FRAMEBUFFER); if (t !== n.FRAMEBUFFER_COMPLETE) throw new Error("Error binding framebuffer: " + UM(n, t)) } function UM(n, t) { switch (t) { case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS"; case n.FRAMEBUFFER_UNSUPPORTED: return "FRAMEBUFFER_UNSUPPORTED"; default: return `unknown error ${t}` } } function cs(n, t, e) { const s = st(n, () => t()); if (s == null) throw new Error(e); return s } function YM(n, t) { const e = n.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, s = t + n.TEXTURE0; if (s < n.TEXTURE0 || s > e) { const o = `[gl.TEXTURE0, gl.TEXTURE${e}]`; throw new Error(`textureUnit must be in ${o}.`) } } function rr(n, t = 2) { return Z(n.slice(0, n.length - t)) } function ir(n) { if (n.length === 0) throw Error("Cannot get rows and columns of an empty shape array."); return [n.length > 1 ? n[n.length - 2] : 1, n[n.length - 1]] } function yl(n) { let t = [1, 1, 1]; return n.length === 0 || n.length === 1 && n[0] === 1 || (t = [rr(n), ...ir(n)]), t } function QM(n, t = !1) { let e = A().getNumber("WEBGL_MAX_TEXTURE_SIZE"), s = A().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE"); s === 1 / 0 && A().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (s = e / 2), t && (e = e * 2, s = s * 2, n = n.map((a, c) => c >= n.length - 2 ? Ol(n[c]) : n[c]), n.length === 1 && (n = [2, n[0]])), n.length !== 2 && (n = ds(n).newShape); let o = Z(n), r = null; n.length <= 1 && o <= e ? r = [1, o] : n.length === 2 && n[0] <= e && n[1] <= e ? r = n : n.length === 3 && n[0] * n[1] <= e && n[2] <= e ? r = [n[0] * n[1], n[2]] : n.length === 3 && n[0] <= e && n[1] * n[2] <= e ? r = [n[0], n[1] * n[2]] : n.length === 4 && n[0] * n[1] * n[2] <= e && n[3] <= e ? r = [n[0] * n[1] * n[2], n[3]] : n.length === 4 && n[0] <= e && n[1] * n[2] * n[3] <= e && (r = [n[0], n[1] * n[2] * n[3]]); const i = r != null && Math.max(...r) > s && Math.min(...r) <= (t ? 2 : 1) && Math.min(...r) > 0; if (r == null || i) if (t) { const a = rr(n); let c = 2, l = 2; n.length && ([c, l] = ir(n)), o = a * (c / 2) * (l / 2), r = Zl(o).map(u => u * 2) } else r = Zl(o); return r } function Il(n) { return n % 2 === 0 } function Cl(n, t) { if (n = n.slice(-2), t = t.slice(-2), Rt(n, t) || !n.length || !t.length || n[0] === 0 || n[1] === 0 || t[0] === 0 || t[1] === 0) return !0; if (n.length !== t.length) { const e = n.slice(-1)[0], s = t.slice(-1)[0]; if (e === s || Il(e) && Il(s) && (n[0] === 1 || t[0] === 1)) return !0 } return n[1] === t[1] && Il(n[0]) && Il(t[0]) } let bp, xp; function JM(n) { if (bp == null) { const t = Mn(n); bp = t.getParameter(t.MAX_TEXTURE_SIZE) } return bp } function jM(n) { if (xp == null) { const t = Mn(n); xp = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS) } return Math.min(16, xp) } function qM(n) { if (n === 0) return 0; let t; const e = Mn(n); return In(e, "EXT_disjoint_timer_query_webgl2") && n === 2 ? t = 2 : In(e, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t } function In(n, t) { return n.getExtension(t) != null } function Hy(n) { try { if (Mn(n) != null) return !0 } catch (t) { return console.log("Error when getting WebGL context: ", t), !1 } return !1 } function tF(n) { if (n === 0) return !1; const t = Mn(n); if (n === 1) { if (!In(t, "OES_texture_float")) return !1 } else if (!In(t, "EXT_color_buffer_float")) return !1; return yp(t) } function eF(n) { if (n === 0) return !1; const t = Mn(n); if (n === 1) { if (!In(t, "OES_texture_float") || !In(t, "WEBGL_color_buffer_float")) return !1 } else { if (In(t, "EXT_color_buffer_float")) return yp(t); const s = "EXT_color_buffer_half_float"; if (In(t, s)) { const o = t.getExtension(s); return nF(t, o) } return !1 } return yp(t) } function yp(n) { const t = fp(n), e = n.createTexture(); n.bindTexture(n.TEXTURE_2D, e); const s = 1, o = 1; n.texImage2D(n.TEXTURE_2D, 0, t.internalFormatFloat, s, o, 0, t.textureFormatFloat, t.textureTypeFloat, null); const r = n.createFramebuffer(); n.bindFramebuffer(n.FRAMEBUFFER, r), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, e, 0); const i = n.checkFramebufferStatus(n.FRAMEBUFFER) === n.FRAMEBUFFER_COMPLETE; return n.bindTexture(n.TEXTURE_2D, null), n.bindFramebuffer(n.FRAMEBUFFER, null), n.deleteTexture(e), n.deleteFramebuffer(r), i } function nF(n, t) { const e = fp(n, t), s = n.createTexture(); n.bindTexture(n.TEXTURE_2D, s); const o = 1, r = 1; n.texImage2D(n.TEXTURE_2D, 0, e.internalFormatHalfFloat, o, r, 0, e.textureFormatFloat, e.textureTypeHalfFloat, null); const i = n.createFramebuffer(); n.bindFramebuffer(n.FRAMEBUFFER, i), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, s, 0); const a = n.checkFramebufferStatus(n.FRAMEBUFFER) === n.FRAMEBUFFER_COMPLETE; return n.bindTexture(n.TEXTURE_2D, null), n.bindFramebuffer(n.FRAMEBUFFER, null), n.deleteTexture(s), n.deleteFramebuffer(i), a } function sF(n) { return n !== 2 ? !1 : Mn(n).fenceSync != null } function qi(n, t) { Array.isArray(n) || (n = [n]), n.forEach(e => { e != null && v(e.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`) }) }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const at = A(); at.registerFlag("HAS_WEBGL", () => at.getNumber("WEBGL_VERSION") > 0), at.registerFlag("WEBGL_VERSION", () => Hy(2) ? 2 : Hy(1) ? 1 : 0), at.registerFlag("WEBGL_CHECK_NUMERICAL_PROBLEMS", () => !1), at.registerFlag("WEBGL_BUFFER_SUPPORTED", () => at.get("WEBGL_VERSION") === 2), at.registerFlag("WEBGL_CPU_FORWARD", () => !0), at.registerFlag("WEBGL_FORCE_F16_TEXTURES", () => !1), at.registerFlag("WEBGL_PACK", () => at.getBool("HAS_WEBGL")), at.registerFlag("WEBGL_PACK_NORMALIZATION", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_CLIP", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_DEPTHWISECONV", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_BINARY_OPERATIONS", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_UNARY_OPERATIONS", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_PACK_REDUCE", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_LAZILY_UNPACK", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_CONV_IM2COL", () => at.getBool("WEBGL_PACK")), at.registerFlag("WEBGL_MAX_TEXTURE_SIZE", () => JM(at.getNumber("WEBGL_VERSION"))), at.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER", () => jM(at.getNumber("WEBGL_VERSION"))), at.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION", () => { const n = at.getNumber("WEBGL_VERSION"); return n === 0 ? 0 : qM(n) }), at.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE", () => at.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 && !nm()), at.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE", () => tF(at.getNumber("WEBGL_VERSION"))), at.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED", () => at.getBool("WEBGL_FORCE_F16_TEXTURES") ? !1 : at.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")), at.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED", () => eF(at.getNumber("WEBGL_VERSION"))), at.registerFlag("WEBGL_FENCE_API_ENABLED", () => sF(at.getNumber("WEBGL_VERSION"))), at.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM", () => at.getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? 4 : 0), at.registerFlag("WEBGL_DELETE_TEXTURE_THRESHOLD", () => -1, n => { if (n < 0 && n !== -1) throw new Error(`WEBGL_DELETE_TEXTURE_THRESHOLD must be -1 (indicating never delete) or at least 0, but got ${n}.`) }), at.registerFlag("WEBGL_FLUSH_THRESHOLD", () => nm() ? 1 : -1, n => { if (n < 0 && n !== -1) throw new Error(`WEBGL_FLUSH_THRESHOLD must be -1 (indicating never manual flush) or at least 0, but got ${n}.`) }), at.registerFlag("CPU_HANDOFF_SIZE_THRESHOLD", () => 128), at.registerFlag("WEBGL_USE_SHAPES_UNIFORMS", () => !1), at.registerFlag("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD", () => 1e5), at.registerFlag("TOPK_K_CPU_HANDOFF_THRESHOLD", () => 128), at.registerFlag("WEBGL_EXP_CONV", () => !1), at.registerFlag("SOFTWARE_WEBGL_ENABLED", () => at.getBool("IS_TEST")), at.registerFlag("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE", () => 1 / 0), at.registerFlag("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE", () => !1), at.registerFlag("WEBGL2_ISNAN_CUSTOM", () => !1), at.registerFlag("ENGINE_COMPILE_ONLY", () => !1);/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Le() {
        let n, t, e, s, o, r, i, a, c, l; return A().getNumber("WEBGL_VERSION") === 2 ? (n = "#version 300 es", t = "in", e = "out", s = "in", o = "texture", r = "outputColor", i = "out vec4 outputColor;", a = A().getBool("WEBGL2_ISNAN_CUSTOM") ? `
      bool isnan_custom(float val) {
        uint floatToUint = floatBitsToUint(val);
        return (floatToUint & 0x7fffffffu) > 0x7f800000u;
      }

      bvec4 isnan_custom(vec4 val) {
        return bvec4(isnan_custom(val.x),
          isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
      }

      #define isnan(value) isnan_custom(value)
    `: "", c = "", l = `
      #define round(value) newRound(value)
      int newRound(float value) {
        return int(floor(value + 0.5));
      }

      ivec4 newRound(vec4 value) {
        return ivec4(floor(value + vec4(0.5)));
      }
    `) : (n = "", t = "attribute", e = "varying", s = "varying", o = "texture2D", r = "gl_FragColor", i = "", a = `
      #define isnan(value) isnan_custom(value)
      bool isnan_custom(float val) {
        return (val > 0. || val < 1. || val == 0.) ? false : true;
      }
      bvec4 isnan_custom(vec4 val) {
        return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
      }
    `, c = `
      uniform float INFINITY;

      bool isinf(float val) {
        return abs(val) == INFINITY;
      }
      bvec4 isinf(vec4 val) {
        return equal(abs(val), vec4(INFINITY));
      }
    `, l = `
      int round(float value) {
        return int(floor(value + 0.5));
      }

      ivec4 round(vec4 value) {
        return ivec4(floor(value + vec4(0.5)));
      }
    `), { version: n, attribute: t, varyingVs: e, varyingFs: s, texture2D: o, output: r, defineOutput: i, defineSpecialNaN: a, defineSpecialInf: c, defineRound: l }
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Io(n, t, e = "index") { const s = ct(t); return s.map((o, r) => { const i = `int ${n[r]} = ${e} / ${o}`, a = r === s.length - 1 ? `int ${n[r + 1]} = ${e} - ${n[r]} * ${o}` : `index -= ${n[r]} * ${o}`; return `${i}; ${a};` }).join("") } function wl(n, t, e = "index") { const s = ct(t); return s.map((o, r) => { const i = `int ${n[r]} = ${e} / outShapeStrides[${r}]`, a = r === s.length - 1 ? `int ${n[r + 1]} = ${e} - ${n[r]} * outShapeStrides[${r}]` : `index -= ${n[r]} * outShapeStrides[${r}]`; return `${i}; ${a};` }).join("") } function oF(n, t) { const e = n.length, s = n.map(r => `${t}[${r}]`), o = new Array(e - 1); o[e - 2] = s[e - 1]; for (let r = e - 3; r >= 0; --r)o[r] = `(${o[r + 1]} * ${s[r + 1]})`; return o } function rF(n, t, e = "index") { const s = n.map((r, i) => i), o = oF(s, t); return o.map((r, i) => { const a = `int ${n[i]} = ${e} / ${o[i]}`, c = i === o.length - 1 ? `int ${n[i + 1]} = ${e} - ${n[i]} * ${o[i]}` : `index -= ${n[i]} * ${o[i]}`; return `${a}; ${c};` }).join("") } function Ip(n) {
        const t = ct(n).map(e => e.toString()); return `
  int getFlatIndex(ivec3 coords) {
    return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
  }
`} function Cp() {
        return `
  int getFlatIndex(ivec3 coords) {
    return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
  }
`} const _y = `
  const float FLOAT_MAX = 1.70141184e38;
  const float FLOAT_MIN = 1.17549435e-38;

  lowp vec4 encode_float(highp float v) {
    if (isnan(v)) {
      return vec4(255, 255, 255, 255);
    }

    highp float av = abs(v);

    if(av < FLOAT_MIN) {
      return vec4(0.0, 0.0, 0.0, 0.0);
    } else if(v > FLOAT_MAX) {
      return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
    } else if(v < -FLOAT_MAX) {
      return vec4(0.0, 0.0,  128.0, 255.0) / 255.0;
    }

    highp vec4 c = vec4(0,0,0,0);

    highp float e = floor(log2(av));
    highp float m = exp2(fract(log2(av))) - 1.0;

    c[2] = floor(128.0 * m);
    m -= c[2] / 128.0;
    c[1] = floor(32768.0 * m);
    m -= c[1] / 32768.0;
    c[0] = floor(8388608.0 * m);

    highp float ebias = e + 127.0;
    c[3] = floor(ebias / 2.0);
    ebias -= c[3] * 2.0;
    c[2] += floor(ebias) * 128.0;

    c[3] += 128.0 * step(0.0, -v);

    return c / 255.0;
  }
`;/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const { getBroadcastDims: Uy } = dT; function iF(n, t, e) {
        const s = []; if (n.forEach(p => { const f = Z(p.shapeInfo.logicalShape); if (p.shapeInfo.isUniform ? s.push(`uniform float ${p.name}${f > 1 ? `[${f}]` : ""};`) : (s.push(`uniform sampler2D ${p.name};`), s.push(`uniform int offset${p.name};`)), e.enableShapeUniforms) { const { uniformShape: m } = wp(e.packedInputs, p.shapeInfo.logicalShape, p.shapeInfo.texShape); switch (m.length) { case 1: s.push(`uniform int ${p.name}Shape;`); break; case 2: s.push(`uniform ivec2 ${p.name}Shape;`); break; case 3: s.push(`uniform ivec3 ${p.name}Shape;`); break; case 4: s.push(`uniform ivec4 ${p.name}Shape;`); break }s.push(`uniform ivec2 ${p.name}TexShape;`) } }), e.enableShapeUniforms) { switch (t.logicalShape.length) { case 1: s.push("uniform int outShape;"); break; case 2: s.push("uniform ivec2 outShape;"), s.push("uniform int outShapeStrides;"); break; case 3: s.push("uniform ivec3 outShape;"), s.push("uniform ivec2 outShapeStrides;"); break; case 4: s.push("uniform ivec4 outShape;"), s.push("uniform ivec3 outShapeStrides;"); break }s.push("uniform ivec2 outTexShape;") } e.customUniforms && e.customUniforms.forEach(p => { s.push(`uniform ${p.type} ${p.name}${p.arrayIndex ? `[${p.arrayIndex}]` : ""};`) }); const o = s.join(`
`), r = n.map(p => aF(p, t, e.packedInputs, e.enableShapeUniforms)).join(`
`), i = t.texShape, a = Le(), c = uF(a); let l, u, d = pF(a); return t.isPacked ? (l = cF(t.logicalShape, i, e.enableShapeUniforms), u = hF(a)) : (l = lF(t.logicalShape, i, e.enableShapeUniforms), u = dF(a)), e.packedInputs && (d += bF), [d, c, u, o, l, r, e.userCode].join(`
`)
    } function ar(n, t = !1) { const e = n.shapeInfo.logicalShape; switch (e.length) { case 0: return $F(n, t); case 1: return LF(n, t); case 2: return DF(n, t); case 3: return MF(n, t); case 4: return VF(n, t); case 5: return zF(n); case 6: return XF(n); default: throw new Error(`${e.length}-D input sampling is not yet supported`) } } function Yy(n, t) { switch (n.shapeInfo.logicalShape.length) { case 0: return RF(n); case 1: return GF(n, t); case 2: return EF(n, t); case 3: return WF(n, t); default: return FF(n, t) } } function aF(n, t, e = !1, s) { let o = ""; e ? o += Yy(n, s) : o += ar(n, s); const r = n.shapeInfo.logicalShape, i = t.logicalShape; return r.length <= i.length && (e ? o += AF(n, t) : o += OF(n, t)), o } function cF(n, t, e) { switch (n.length) { case 0: return Qy(); case 1: return xF(n, t, e); case 2: return TF(n, t, e); case 3: return IF(n, t, e); default: return wF(n, t, e) } } function lF(n, t, e) { switch (n.length) { case 0: return Qy(); case 1: return yF(n, t, e); case 2: return NF(n, t, e); case 3: return CF(n, t, e); case 4: return vF(n, t, e); case 5: return SF(n, t); case 6: return kF(n, t); default: throw new Error(`${n.length}-D output sampling is not yet supported`) } } function uF(n) {
        return `
    float sampleTexture(sampler2D textureSampler, vec2 uv) {
      return ${n.texture2D}(textureSampler, uv).r;
    }
  `} function dF(n) {
        return `
    void setOutput(float val) {
      ${n.output} = vec4(val, 0, 0, 0);
    }
  `} function hF(n) {
        return `
    void setOutput(vec4 val) {
      ${n.output} = val;
    }
  `} function pF(n) {
        return `${n.version}
    precision highp float;
    precision highp int;
    precision highp sampler2D;
    ${n.varyingFs} vec2 resultUV;
    ${n.defineOutput}
    const vec2 halfCR = vec2(0.5, 0.5);

    struct ivec5
    {
      int x;
      int y;
      int z;
      int w;
      int u;
    };

    struct ivec6
    {
      int x;
      int y;
      int z;
      int w;
      int u;
      int v;
    };

    uniform float NAN;
    ${n.defineSpecialNaN}
    ${n.defineSpecialInf}
    ${n.defineRound}

    int imod(int x, int y) {
      return x - y * (x / y);
    }

    int idiv(int a, int b, float sign) {
      int res = a / b;
      int mod = imod(a, b);
      if (sign < 0. && mod != 0) {
        res -= 1;
      }
      return res;
    }

    //Based on the work of Dave Hoskins
    //https://www.shadertoy.com/view/4djSRW
    #define HASHSCALE1 443.8975
    float random(float seed){
      vec2 p = resultUV * seed;
      vec3 p3  = fract(vec3(p.xyx) * HASHSCALE1);
      p3 += dot(p3, p3.yzx + 19.19);
      return fract((p3.x + p3.y) * p3.z);
    }

    ${fF}
    ${mF}
    ${gF}
  `} const fF = `
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
  int texR = index / texNumC;
  int texC = index - texR * texNumC;
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
  int texelIndex = index / 2;
  int texR = texelIndex / texNumC;
  int texC = texelIndex - texR * texNumC;
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, mF = `
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
  int texNumC, int row, int col) {
  int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
  int texR = texelIndex / texNumC;
  int texC = texelIndex - texR * texNumC;
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, gF = `
vec2 packedUVfrom3D(int texNumR, int texNumC,
    int texelsInBatch, int texelsInLogicalRow, int b,
    int row, int col) {
  int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
  int texR = index / texNumC;
  int texC = index - texR * texNumC;
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
}
`, bF = `
  float getChannel(vec4 frag, vec2 innerDims) {
    vec2 modCoord = mod(innerDims, 2.);
    return modCoord.x == 0. ?
      (modCoord.y == 0. ? frag.r : frag.g) :
      (modCoord.y == 0. ? frag.b : frag.a);
  }
  float getChannel(vec4 frag, int dim) {
    float modCoord = mod(float(dim), 2.);
    return modCoord == 0. ? frag.r : frag.g;
  }
`; function Qy() {
        return `
    int getOutputCoords() {
      return 0;
    }
  `} function xF(n, t, e) {
        const s = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)]; return s[0] === 1 ? e ? `
      int getOutputCoords() {
        return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));
      }
    `: `
      int getOutputCoords() {
        return 2 * int(resultUV.x * ${s[1]}.0);
      }
    `: s[1] === 1 ? e ? `
      int getOutputCoords() {
        return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));
      }
    `: `
      int getOutputCoords() {
        return 2 * int(resultUV.y * ${s[0]}.0);
      }
    `: e ? `
    int getOutputCoords() {
      ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(packedTexShape[0], packedTexShape[1]));
      return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);
    }
  `: `
    int getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${s[0]}, ${s[1]}));
      return 2 * (resTexRC.x * ${s[1]} + resTexRC.y);
    }
  `} function yF(n, t, e) {
        return t[0] === 1 ? e ? `
      int getOutputCoords() {
        return int(resultUV.x * float(outTexShape[1]));
      }
    `: `
      int getOutputCoords() {
        return int(resultUV.x * ${t[1]}.0);
      }
    `: t[1] === 1 ? e ? `
      int getOutputCoords() {
        return int(resultUV.y * float(outTexShape[0]));
      }
    `: `
      int getOutputCoords() {
        return int(resultUV.y * ${t[0]}.0);
      }
    `: e ? `
    int getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(outTexShape[0], outTexShape[1]));
      return resTexRC.x * outTexShape[1] + resTexRC.y;
    }
  `: `
    int getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${t[0]}, ${t[1]}));
      return resTexRC.x * ${t[1]} + resTexRC.y;
    }
  `} function IF(n, t, e) {
        if (e) return `
    ivec3 getOutputCoords() {
      ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
      int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));
      int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(packedTexShape[0], packedTexShape[1]));
      int index = resTexRC.x * packedTexShape[1] + resTexRC.y;

      int b = index / texelsInBatch;
      index -= b * texelsInBatch;

      int r = 2 * (index / texelsInLogicalRow);
      int c = imod(index, texelsInLogicalRow) * 2;

      return ivec3(b, r, c);
    }
  `; const s = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(n[2] / 2), r = o * Math.ceil(n[1] / 2); return `
    ivec3 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${s[0]}, ${s[1]}));
      int index = resTexRC.x * ${s[1]} + resTexRC.y;

      int b = index / ${r};
      index -= b * ${r};

      int r = 2 * (index / ${o});
      int c = imod(index, ${o}) * 2;

      return ivec3(b, r, c);
    }
  `} function CF(n, t, e) {
        if (e) return `
  ivec3 getOutputCoords() {
    ivec2 resTexRC = ivec2(resultUV.yx *
                           vec2(outTexShape[0], outTexShape[1]));
    int index = resTexRC.x * outTexShape[1] + resTexRC.y;
    ${wl(["r", "c", "d"], n)}
    return ivec3(r, c, d);
  }
`; const s = Io(["r", "c", "d"], n); return `
    ivec3 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${t[0]}, ${t[1]}));
      int index = resTexRC.x * ${t[1]} + resTexRC.y;
      ${s}
      return ivec3(r, c, d);
    }
  `} function wF(n, t, e) {
        if (e) return `
    ivec4 getOutputCoords() {
      ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(packedTexShape[0], packedTexShape[1]));
      int index = resTexRC.x * packedTexShape[1] + resTexRC.y;

      int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));
      int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));
      int texelsInBatchN = texelsInBatch * outShape[1];

      int b2 = index / texelsInBatchN;
      index -= b2 * texelsInBatchN;

      int b = index / texelsInBatch;
      index -= b * texelsInBatch;

      int r = 2 * (index / texelsInLogicalRow);
      int c = imod(index, texelsInLogicalRow) * 2;

      return ivec4(b2, b, r, c);
    }
  `; const s = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(n[n.length - 1] / 2), r = o * Math.ceil(n[n.length - 2] / 2); let i = r, a = "", c = "b, r, c"; for (let l = 2; l < n.length - 1; l++)i *= n[n.length - l - 1], a = `
      int b${l} = index / ${i};
      index -= b${l} * ${i};
    `+ a, c = `b${l}, ` + c; return `
    ivec${n.length} getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${s[0]}, ${s[1]}));
      int index = resTexRC.x * ${s[1]} + resTexRC.y;

      ${a}

      int b = index / ${r};
      index -= b * ${r};

      int r = 2 * (index / ${o});
      int c = imod(index, ${o}) * 2;

      return ivec${n.length}(${c});
    }
  `} function vF(n, t, e) {
        if (e) return `
    ivec4 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
        vec2(outTexShape[0], outTexShape[1]));
      int index = resTexRC.x * outTexShape[1] + resTexRC.y;
      ${wl(["r", "c", "d", "d2"], n)}
      return ivec4(r, c, d, d2);
    }
  `; const s = Io(["r", "c", "d", "d2"], n); return `
    ivec4 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
        vec2(${t[0]}, ${t[1]}));
      int index = resTexRC.x * ${t[1]} + resTexRC.y;
      ${s}
      return ivec4(r, c, d, d2);
    }
  `} function SF(n, t) {
        const e = Io(["r", "c", "d", "d2", "d3"], n); return `
    ivec5 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
                             ${t[1]}));

      int index = resTexRC.x * ${t[1]} + resTexRC.y;

      ${e}

      ivec5 outShape = ivec5(r, c, d, d2, d3);
      return outShape;
    }
  `} function kF(n, t) {
        const e = Io(["r", "c", "d", "d2", "d3", "d4"], n); return `
    ivec6 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
        vec2(${t[0]}, ${t[1]}));
      int index = resTexRC.x * ${t[1]} + resTexRC.y;

      ${e}

      ivec6 result = ivec6(r, c, d, d2, d3, d4);
      return result;
    }
  `} function TF(n, t, e) {
        const s = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)]; if (Rt(n, t)) return e ? `
      ivec2 getOutputCoords() {
        ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
        return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));
      }
    `: `
      ivec2 getOutputCoords() {
        return 2 * ivec2(resultUV.yx * vec2(${s[0]}, ${s[1]}));
      }
    `; const o = Math.ceil(n[1] / 2); return e ? `
    ivec2 getOutputCoords() {
      ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
      int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(packedTexShape[0], packedTexShape[1]));

      int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
      int r = 2 * (index / texelsInLogicalRow);
      int c = imod(index, texelsInLogicalRow) * 2;

      return ivec2(r, c);
    }
  `: `
    ivec2 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${s[0]}, ${s[1]}));

      int index = resTexRC.x * ${s[1]} + resTexRC.y;
      int r = 2 * (index / ${o});
      int c = imod(index, ${o}) * 2;

      return ivec2(r, c);
    }
  `} function NF(n, t, e) {
        return Rt(n, t) ? e ? `
      ivec2 getOutputCoords() {
        return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
      }
    `: `
      ivec2 getOutputCoords() {
        return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
      }
    `: n[1] === 1 ? e ? `
      ivec2 getOutputCoords() {
        ivec2 resTexRC = ivec2(resultUV.yx *
                               vec2(outTexShape[0], outTexShape[1]));
        int index = resTexRC.x * outTexShape[1] + resTexRC.y;
        return ivec2(index, 0);
      }
    `: `
      ivec2 getOutputCoords() {
        ivec2 resTexRC = ivec2(resultUV.yx *
                               vec2(${t[0]}, ${t[1]}));
        int index = resTexRC.x * ${t[1]} + resTexRC.y;
        return ivec2(index, 0);
      }
    `: n[0] === 1 ? e ? `
      ivec2 getOutputCoords() {
        ivec2 resTexRC = ivec2(resultUV.yx *
                               vec2(outTexShape[0], outTexShape[1]));
        int index = resTexRC.x * outTexShape[1] + resTexRC.y;
        return ivec2(0, index);
      }
    `: `
      ivec2 getOutputCoords() {
        ivec2 resTexRC = ivec2(resultUV.yx *
                               vec2(${t[0]}, ${t[1]}));
        int index = resTexRC.x * ${t[1]} + resTexRC.y;
        return ivec2(0, index);
      }
    `: e ? `
    ivec2 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(outTexShape[0], outTexShape[1]));
      int index = resTexRC.x * outTexShape[1] + resTexRC.y;
      int r = index / outShape[1];
      int c = index - r * outShape[1];
      return ivec2(r, c);
    }
  `: `
    ivec2 getOutputCoords() {
      ivec2 resTexRC = ivec2(resultUV.yx *
                             vec2(${t[0]}, ${t[1]}));
      int index = resTexRC.x * ${t[1]} + resTexRC.y;
      int r = index / ${n[1]};
      int c = index - r * ${n[1]};
      return ivec2(r, c);
    }
  `} function Co(n) { return `offset${n}` } function RF(n) {
        const t = n.name, e = "get" + t.charAt(0).toUpperCase() + t.slice(1), s = Le(); return `
    vec4 ${e}() {
      return ${s.texture2D}(${t}, halfCR);
    }
  `} function $F(n, t) {
        const e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1); if (n.shapeInfo.isUniform) return `float ${s}() {return ${e};}`; const [o, r] = n.shapeInfo.texShape; if (o === 1 && r === 1) return `
      float ${s}() {
        return sampleTexture(${e}, halfCR);
      }
    `; const i = Co(e); if (t) return `
    float ${s}() {
      vec2 uv = uvFromFlat(${e}TexShape[0], ${e}TexShape[1], ${i});
      return sampleTexture(${e}, uv);
    }
  `; const [a, c] = n.shapeInfo.texShape; return `
    float ${s}() {
      vec2 uv = uvFromFlat(${a}, ${c}, ${i});
      return sampleTexture(${e}, uv);
    }
  `} function GF(n, t) {
        const e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1), o = n.shapeInfo.texShape, r = Le(); if (t) return `
    vec4 ${s}(int index) {
      ivec2 packedTexShape = ivec2(ceil(float(${e}TexShape[0]) / 2.0), ceil(float(${e}TexShape[1]) / 2.0));
      vec2 uv = packedUVfrom1D(
        packedTexShape[0], packedTexShape[1], index);
      return ${r.texture2D}(${e}, uv);
    }
  `; const i = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)]; return `
    vec4 ${s}(int index) {
      vec2 uv = packedUVfrom1D(
        ${i[0]}, ${i[1]}, index);
      return ${r.texture2D}(${e}, uv);
    }
  `} function LF(n, t) {
        const e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1); if (n.shapeInfo.isUniform) return `
      float ${s}(int index) {
        ${cr(n)}
      }
    `; const o = n.shapeInfo.texShape, r = o[0], i = o[1]; if (i === 1 && r === 1) return `
      float ${s}(int index) {
        return sampleTexture(${e}, halfCR);
      }
    `; const a = Co(e); return i === 1 ? t ? `
      float ${s}(int index) {
        vec2 uv = vec2(0.5, (float(index + ${a}) + 0.5) / float(${e}TexShape[0]));
        return sampleTexture(${e}, uv);
      }
    `: `
      float ${s}(int index) {
        vec2 uv = vec2(0.5, (float(index + ${a}) + 0.5) / ${r}.0);
        return sampleTexture(${e}, uv);
      }
    `: r === 1 ? t ? `
      float ${s}(int index) {
        vec2 uv = vec2((float(index + ${a}) + 0.5) / float(${e}TexShape[1]), 0.5);
        return sampleTexture(${e}, uv);
      }
    `: `
      float ${s}(int index) {
        vec2 uv = vec2((float(index + ${a}) + 0.5) / ${i}.0, 0.5);
        return sampleTexture(${e}, uv);
      }
    `: t ? `
    float ${s}(int index) {
      vec2 uv = uvFromFlat(${e}TexShape[0], ${e}TexShape[1], index + ${a});
      return sampleTexture(${e}, uv);
    }
  `: `
    float ${s}(int index) {
      vec2 uv = uvFromFlat(${r}, ${i}, index + ${a});
      return sampleTexture(${e}, uv);
    }
  `} function EF(n, t) {
        const e = n.shapeInfo.logicalShape, s = n.name, o = "get" + s.charAt(0).toUpperCase() + s.slice(1), r = n.shapeInfo.texShape, i = r[0], a = r[1], c = Le(); if (r != null && Rt(e, r)) return t ? `
      vec4 ${o}(int row, int col) {
        vec2 uv = (vec2(col, row) + halfCR) / vec2(${s}TexShape[1], ${s}TexShape[0]);

        return ${c.texture2D}(${s}, uv);
      }
    `: `
      vec4 ${o}(int row, int col) {
        vec2 uv = (vec2(col, row) + halfCR) / vec2(${a}.0, ${i}.0);

        return ${c.texture2D}(${s}, uv);
      }
    `; if (t) return `
    vec4 ${o}(int row, int col) {
      ivec2 packedTexShape = ivec2(ceil(float(${s}TexShape[0]) / 2.0), ceil(float(${s}TexShape[1]) / 2.0));
      int valuesPerRow = int(ceil(float(${s}Shape[1]) / 2.0));
      vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
      return ${c.texture2D}(${s}, uv);
    }
  `; const l = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)], u = Math.ceil(e[1] / 2); return `
    vec4 ${o}(int row, int col) {
      vec2 uv = packedUVfrom2D(${u}, ${l[0]}, ${l[1]}, row, col);
      return ${c.texture2D}(${s}, uv);
    }
  `} function DF(n, t) {
        const e = n.shapeInfo.logicalShape, s = n.name, o = "get" + s.charAt(0).toUpperCase() + s.slice(1), r = n.shapeInfo.texShape; if (r != null && Rt(e, r)) {
            if (t) return `
      float ${o}(int row, int col) {
        vec2 uv = (vec2(col, row) + halfCR) / vec2(${s}TexShape[1], ${s}TexShape[0]);
        return sampleTexture(${s}, uv);
      }
    `; const h = r[0], p = r[1]; return `
    float ${o}(int row, int col) {
      vec2 uv = (vec2(col, row) + halfCR) / vec2(${p}.0, ${h}.0);
      return sampleTexture(${s}, uv);
    }
  `} const { newShape: i, keptDims: a } = ds(e), c = i; if (c.length < e.length) {
            const h = lr(n, c), p = ["row", "col"]; return `
      ${ar(h, t)}
      float ${o}(int row, int col) {
        return ${o}(${ur(p, a)});
      }
    `} if (n.shapeInfo.isUniform) return `
      float ${o}(int row, int col) {
        int index = round(dot(vec2(row, col), vec2(${e[1]}, 1)));
        ${cr(n)}
      }
    `; const l = r[0], u = r[1], d = Co(s); return u === 1 ? t ? `
      float ${o}(int row, int col) {
        float index = dot(vec3(row, col, ${d}), vec3(${s}Shape[1], 1, 1));
        vec2 uv = vec2(0.5, (index + 0.5) / float(${s}TexShape[0]));
        return sampleTexture(${s}, uv);
      }
    `: `
    float ${o}(int row, int col) {
      float index = dot(vec3(row, col, ${d}), vec3(${e[1]}, 1, 1));
      vec2 uv = vec2(0.5, (index + 0.5) / ${l}.0);
      return sampleTexture(${s}, uv);
    }
  `: l === 1 ? t ? `
      float ${o}(int row, int col) {
        float index = dot(vec3(row, col, ${d}), vec3(${s}Shape[1], 1, 1));
        vec2 uv = vec2((index + 0.5) / float(${s}TexShape[1]), 0.5);
        return sampleTexture(${s}, uv);
      }
    `: `
    float ${o}(int row, int col) {
      float index = dot(vec3(row, col, ${d}), vec3(${e[1]}, 1, 1));
      vec2 uv = vec2((index + 0.5) / ${u}.0, 0.5);
      return sampleTexture(${s}, uv);
    }
  `: t ? `
      float ${o}(int row, int col) {
        // Explicitly use integer operations as dot() only works on floats.
        int index = row * ${s}Shape[1] + col + ${d};
        vec2 uv = uvFromFlat(${s}TexShape[0], ${s}TexShape[1], index);
        return sampleTexture(${s}, uv);
      }
    `: `
  float ${o}(int row, int col) {
    // Explicitly use integer operations as dot() only works on floats.
    int index = row * ${e[1]} + col + ${d};
    vec2 uv = uvFromFlat(${l}, ${u}, index);
    return sampleTexture(${s}, uv);
  }
`} function WF(n, t) {
        const e = n.shapeInfo.logicalShape, s = n.name, o = "get" + s.charAt(0).toUpperCase() + s.slice(1), r = n.shapeInfo.texShape, i = [Math.ceil(r[0] / 2), Math.ceil(r[1] / 2)]; if (e[0] === 1) {
            const h = e.slice(1), p = [1, 2], f = lr(n, h), m = ["b", "row", "col"]; return `
        ${Yy(f, t)}
        vec4 ${o}(int b, int row, int col) {
          return ${o}(${ur(m, p)});
        }
      `} const a = Le(); if (t) return `
    vec4 ${o}(int b, int row, int col) {
      ivec2 packedTexShape = ivec2(ceil(float(${s}TexShape[0]) / 2.0), ceil(float(${s}TexShape[1]) / 2.0));
      int valuesPerRow = int(ceil(float(${s}Shape[2]) / 2.0));
      int texelsInBatch = valuesPerRow * int(ceil(float(${s}Shape[1]) / 2.0));
      vec2 uv = packedUVfrom3D(
        packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
      return ${a.texture2D}(${s}, uv);
    }
  `; const c = i[0], l = i[1], u = Math.ceil(e[2] / 2), d = u * Math.ceil(e[1] / 2); return `
    vec4 ${o}(int b, int row, int col) {
      vec2 uv = packedUVfrom3D(
        ${c}, ${l}, ${d}, ${u}, b, row, col);
      return ${a.texture2D}(${s}, uv);
    }
  `} function MF(n, t) {
        const e = n.shapeInfo.logicalShape, s = n.name, o = "get" + s.charAt(0).toUpperCase() + s.slice(1), r = e[1] * e[2], i = e[2], { newShape: a, keptDims: c } = ds(e), l = a; if (l.length < e.length) {
            const m = lr(n, l), g = ["row", "col", "depth"]; return `
        ${ar(m, t)}
        float ${o}(int row, int col, int depth) {
          return ${o}(${ur(g, c)});
        }
      `} if (n.shapeInfo.isUniform) return `
      float ${o}(int row, int col, int depth) {
        int index = round(dot(vec3(row, col, depth),
                          vec3(${r}, ${i}, 1)));
        ${cr(n)}
      }
    `; const u = n.shapeInfo.texShape, d = u[0], h = u[1], p = n.shapeInfo.flatOffset; if (h === r && p == null) return t ? `
      float ${o}(int row, int col, int depth) {
        int stride1 = ${s}Shape[2];
        float texR = float(row);
        float texC = dot(vec2(col, depth), vec2(stride1, 1));
        vec2 uv = (vec2(texC, texR) + halfCR) /
                   vec2(${s}TexShape[1], ${s}TexShape[0]);
        return sampleTexture(${s}, uv);
      }
    `: `
        float ${o}(int row, int col, int depth) {
          float texR = float(row);
          float texC = dot(vec2(col, depth), vec2(${i}, 1));
          vec2 uv = (vec2(texC, texR) + halfCR) /
                     vec2(${h}.0, ${d}.0);
          return sampleTexture(${s}, uv);
        }
      `; if (h === i && p == null) return t ? `
      float ${o}(int row, int col, int depth) {
        float texR = dot(vec2(row, col), vec2(${s}Shape[1], 1));
        float texC = float(depth);
        vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${s}TexShape[1], ${s}TexShape[0]);
        return sampleTexture(${s}, uv);
      }
    `: `
    float ${o}(int row, int col, int depth) {
      float texR = dot(vec2(row, col), vec2(${e[1]}, 1));
      float texC = float(depth);
      vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${h}.0, ${d}.0);
      return sampleTexture(${s}, uv);
    }
  `; const f = Co(s); return t ? `
    float ${o}(int row, int col, int depth) {
      // Explicitly use integer operations as dot() only works on floats.
      int stride0 = ${s}Shape[1] * ${s}Shape[2];
      int stride1 = ${s}Shape[2];
      int index = row * stride0 + col * stride1 + depth + ${f};
      vec2 uv = uvFromFlat(${s}TexShape[0], ${s}TexShape[1], index);
      return sampleTexture(${s}, uv);
    }
    `: `
      float ${o}(int row, int col, int depth) {
        // Explicitly use integer operations as dot() only works on floats.
        int index = row * ${r} + col * ${i} + depth + ${f};
        vec2 uv = uvFromFlat(${d}, ${h}, index);
        return sampleTexture(${s}, uv);
      }
  `} function FF(n, t) {
        const e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1), o = Le(); if (t) return `
    vec4 ${s}(int b2, int b, int row, int col) {
      int valuesPerRow = int(ceil(float(${e}Shape[3]) / 2.0));
      int texelsInBatch = valuesPerRow * int(ceil(float(${e}Shape[2]) / 2.0));
      int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
      texelsInBatch *= ${e}Shape[1];
      index = b2 * texelsInBatch + index;
      ivec2 packedTexShape = ivec2(ceil(float(${e}TexShape[0]) / 2.0), ceil(float(${e}TexShape[1]) / 2.0));
      int texR = index / packedTexShape[1];
      int texC = index - texR * packedTexShape[1];
      vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${o.texture2D}(${e}, uv);
    }
  `; const r = n.shapeInfo.logicalShape, i = r.length, a = n.shapeInfo.texShape, c = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], l = c[0], u = c[1], d = Math.ceil(r[i - 1] / 2); let h = d * Math.ceil(r[i - 2] / 2), p = "int b, int row, int col", f = `b * ${h} + (row / 2) * ${d} + (col / 2)`; for (let m = 2; m < i - 1; m++)p = `int b${m}, ` + p, h *= r[i - m - 1], f = `b${m} * ${h} + ` + f; return `
    vec4 ${s}(${p}) {
      int index = ${f};
      int texR = index / ${u};
      int texC = index - texR * ${u};
      vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${u}, ${l});
      return ${o.texture2D}(${e}, uv);
    }
  `} function VF(n, t) {
        const e = n.shapeInfo.logicalShape, s = n.name, o = "get" + s.charAt(0).toUpperCase() + s.slice(1), r = e[3], i = e[2] * r, a = e[1] * i, { newShape: c, keptDims: l } = ds(e); if (c.length < e.length) {
            const x = lr(n, c), I = ["row", "col", "depth", "depth2"]; return `
      ${ar(x, t)}
      float ${o}(int row, int col, int depth, int depth2) {
        return ${o}(${ur(I, l)});
      }
    `} if (n.shapeInfo.isUniform) return `
      float ${o}(int row, int col, int depth, int depth2) {
        int index = round(dot(vec4(row, col, depth, depth2),
                          vec4(${a}, ${i}, ${r}, 1)));
        ${cr(n)}
      }
    `; const u = n.shapeInfo.flatOffset, d = n.shapeInfo.texShape, h = d[0], p = d[1], f = `int stride2 = ${s}Shape[3];`, m = `int stride1 = ${s}Shape[2] * stride2;`, g = `int stride0 = ${s}Shape[1] * stride1;`; if (p === a && u == null) return t ? `
      float ${o}(int row, int col, int depth, int depth2) {
        ${f}
        ${m}
        float texR = float(row);
        float texC =
            dot(vec3(col, depth, depth2),
                vec3(stride1, stride2, 1));
        vec2 uv = (vec2(texC, texR) + halfCR) /
                   vec2(${s}TexShape[1], ${s}TexShape[0]);
        return sampleTexture(${s}, uv);
      }
    `: `
      float ${o}(int row, int col, int depth, int depth2) {
        float texR = float(row);
        float texC =
            dot(vec3(col, depth, depth2),
                vec3(${i}, ${r}, 1));
        vec2 uv = (vec2(texC, texR) + halfCR) /
                   vec2(${p}.0, ${h}.0);
        return sampleTexture(${s}, uv);
      }
    `; if (p === r && u == null) return t ? `
      float ${o}(int row, int col, int depth, int depth2) {
        float texR = dot(vec3(row, col, depth),
                         vec3(${s}Shape[1] * ${s}Shape[2], ${s}Shape[2], 1));
        float texC = float(depth2);
        vec2 uv = (vec2(texC, texR) + halfCR) /
                  vec2(${s}TexShape[1], ${s}TexShape[0]);
        return sampleTexture(${s}, uv);
      }
    `: `
      float ${o}(int row, int col, int depth, int depth2) {
        float texR = dot(vec3(row, col, depth),
                         vec3(${e[1] * e[2]}, ${e[2]}, 1));
        float texC = float(depth2);
        vec2 uv = (vec2(texC, texR) + halfCR) /
                  vec2(${p}.0, ${h}.0);
        return sampleTexture(${s}, uv);
      }
    `; const b = Co(s); return t ? `
    float ${o}(int row, int col, int depth, int depth2) {
      // Explicitly use integer operations as dot() only works on floats.
      ${f}
      ${m}
      ${g}
      int index = row * stride0 + col * stride1 +
          depth * stride2 + depth2;
      vec2 uv = uvFromFlat(${s}TexShape[0], ${s}TexShape[1], index + ${b});
      return sampleTexture(${s}, uv);
    }
  `: `
    float ${o}(int row, int col, int depth, int depth2) {
      // Explicitly use integer operations as dot() only works on floats.
      int index = row * ${a} + col * ${i} +
          depth * ${r} + depth2;
      vec2 uv = uvFromFlat(${h}, ${p}, index + ${b});
      return sampleTexture(${s}, uv);
    }
  `} function zF(n) {
        const t = n.shapeInfo.logicalShape, e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1), o = t[4], r = t[3] * o, i = t[2] * r, a = t[1] * i, { newShape: c, keptDims: l } = ds(t); if (c.length < t.length) {
            const m = lr(n, c), g = ["row", "col", "depth", "depth2", "depth3"]; return `
      ${ar(m)}
      float ${s}(int row, int col, int depth, int depth2, int depth3) {
        return ${s}(${ur(g, l)});
      }
    `} if (n.shapeInfo.isUniform) return `
      float ${s}(int row, int col, int depth, int depth2, int depth3) {
        float index = dot(
          vec4(row, col, depth, depth2),
          vec4(${a}, ${i}, ${r}, ${o})) +
          depth3;
        ${cr(n)}
      }
    `; const u = n.shapeInfo.flatOffset, d = n.shapeInfo.texShape, h = d[0], p = d[1]; if (p === a && u == null) return `
      float ${s}(int row, int col, int depth, int depth2, int depth3) {
        int texR = row;
        float texC = dot(vec4(col, depth, depth2, depth3),
                         vec4(${i}, ${r}, ${o}, 1));
        vec2 uv = (vec2(texC, texR) + halfCR) /
                   vec2(${p}.0, ${h}.0);
        return sampleTexture(${e}, uv);
      }
    `; if (p === o && u == null) return `
      float ${s}(int row, int col, int depth, int depth2, int depth3) {
        float texR = dot(
          vec4(row, col, depth, depth2),
          vec4(${t[1] * t[2] * t[3]},
               ${t[2] * t[3]}, ${t[3]}, 1));
        int texC = depth3;
        vec2 uv = (vec2(texC, texR) + halfCR) /
                  vec2(${p}.0, ${h}.0);
        return sampleTexture(${e}, uv);
      }
    `; const f = Co(e); return `
    float ${s}(int row, int col, int depth, int depth2, int depth3) {
      // Explicitly use integer operations as dot() only works on floats.
      int index = row * ${a} + col * ${i} + depth * ${r} +
          depth2 * ${o} + depth3 + ${f};
      vec2 uv = uvFromFlat(${h}, ${p}, index);
      return sampleTexture(${e}, uv);
    }
  `} function XF(n) {
        const t = n.shapeInfo.logicalShape, e = n.name, s = "get" + e.charAt(0).toUpperCase() + e.slice(1), { newShape: o, keptDims: r } = ds(t); if (o.length < t.length) {
            const g = lr(n, o), b = ["row", "col", "depth", "depth2", "depth3", "depth4"]; return `
      ${ar(g)}
      float ${s}(int row, int col, int depth,
                    int depth2, int depth3, int depth4) {
        return ${s}(${ur(b, r)});
      }
    `} const i = t[5], a = t[4] * i, c = t[3] * a, l = t[2] * c, u = t[1] * l; if (n.shapeInfo.isUniform) return `
      float ${s}(int row, int col, int depth,
                  int depth2, int depth3, int depth4) {
        int index = round(dot(
          vec4(row, col, depth, depth2),
          vec4(${u}, ${l}, ${c}, ${a})) +
          dot(
            vec2(depth3, depth4),
            vec2(${i}, 1)));
        ${cr(n)}
      }
    `; const d = n.shapeInfo.flatOffset, h = n.shapeInfo.texShape, p = h[0], f = h[1]; if (f === u && d == null) return `
      float ${s}(int row, int col, int depth,
                    int depth2, int depth3, int depth4) {
        int texR = row;
        float texC = dot(vec4(col, depth, depth2, depth3),
          vec4(${l}, ${c}, ${a}, ${i})) +
               float(depth4);
        vec2 uv = (vec2(texC, texR) + halfCR) /
                   vec2(${f}.0, ${p}.0);
        return sampleTexture(${e}, uv);
      }
    `; if (f === i && d == null) return `
      float ${s}(int row, int col, int depth,
                    int depth2, int depth3, int depth4) {
        float texR = dot(vec4(row, col, depth, depth2),
          vec4(${t[1] * t[2] * t[3] * t[4]},
               ${t[2] * t[3] * t[4]},
               ${t[3] * t[4]},
               ${t[4]})) + float(depth3);
        int texC = depth4;
        vec2 uv = (vec2(texC, texR) + halfCR) /
                  vec2(${f}.0, ${p}.0);
        return sampleTexture(${e}, uv);
      }
    `; const m = Co(e); return `
    float ${s}(int row, int col, int depth,
                  int depth2, int depth3, int depth4) {
      // Explicitly use integer operations as dot() only works on floats.
      int index = row * ${u} + col * ${l} + depth * ${c} +
          depth2 * ${a} + depth3 * ${i} + depth4 + ${m};
      vec2 uv = uvFromFlat(${p}, ${f}, index);
      return sampleTexture(${e}, uv);
    }
  `} function cr(n) {
        const t = n.name, e = Z(n.shapeInfo.logicalShape); return e < 2 ? `return ${t};` : `
    for (int i = 0; i < ${e}; i++) {
      if (i == index) {
        return ${t}[i];
      }
    }
  `} function AF(n, t) {
        const e = n.name, s = e.charAt(0).toUpperCase() + e.slice(1), o = "get" + s + "AtOutCoords", r = n.shapeInfo.logicalShape.length, i = t.logicalShape.length, a = Uy(n.shapeInfo.logicalShape, t.logicalShape), c = Xt(i), l = i - r; let u; const d = ["x", "y", "z", "w", "u", "v"]; r === 0 ? u = "" : i < 2 && a.length >= 1 ? u = "coords = 0;" : u = a.map(x => `coords.${d[x + l]} = 0;`).join(`
`); let h = ""; i < 2 && r > 0 ? h = "coords" : h = n.shapeInfo.logicalShape.map((x, I) => `coords.${d[I + l]}`).join(", "); let p = "return outputValue;"; const m = Z(n.shapeInfo.logicalShape) === 1, b = Z(t.logicalShape) === 1; if (r === 1 && !m && !b) p = `
      return vec4(outputValue.xy, outputValue.xy);
    `; else if (m && !b) i === 1 ? p = `
        return vec4(outputValue.x, outputValue.x, 0., 0.);
      `: p = `
        return vec4(outputValue.x);
      `; else if (a.length) { const x = r - 2, I = r - 1; a.indexOf(x) > -1 && a.indexOf(I) > -1 ? p = "return vec4(outputValue.x);" : a.indexOf(x) > -1 ? p = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : a.indexOf(I) > -1 && (p = "return vec4(outputValue.xx, outputValue.zz);") } return `
    vec4 ${o}() {
      ${c} coords = getOutputCoords();
      ${u}
      vec4 outputValue = get${s}(${h});
      ${p}
    }
  `} function OF(n, t) {
        const e = n.name, s = e.charAt(0).toUpperCase() + e.slice(1), o = "get" + s + "AtOutCoords", r = t.texShape, i = n.shapeInfo.texShape, a = n.shapeInfo.logicalShape.length, c = t.logicalShape.length; if (!n.shapeInfo.isUniform && a === c && n.shapeInfo.flatOffset == null && Rt(i, r)) return `
      float ${o}() {
        return sampleTexture(${e}, resultUV);
      }
    `; const l = Xt(c), u = Uy(n.shapeInfo.logicalShape, t.logicalShape), d = c - a; let h; const p = ["x", "y", "z", "w", "u", "v"]; a === 0 ? h = "" : c < 2 && u.length >= 1 ? h = "coords = 0;" : h = u.map(m => `coords.${p[m + d]} = 0;`).join(`
`); let f = ""; return c < 2 && a > 0 ? f = "coords" : f = n.shapeInfo.logicalShape.map((m, g) => `coords.${p[g + d]}`).join(", "), `
    float ${o}() {
      ${l} coords = getOutputCoords();
      ${h}
      return get${s}(${f});
    }
  `} function Xt(n) { if (n <= 1) return "int"; if (n === 2) return "ivec2"; if (n === 3) return "ivec3"; if (n === 4) return "ivec4"; if (n === 5) return "ivec5"; if (n === 6) return "ivec6"; throw Error(`GPU for rank ${n} is not yet supported`) } function wp(n, t, e) { const { newShape: s, keptDims: o } = ds(t), r = t.length, i = n && r === 3 && t[0] === 1, a = i ? t.slice(1) : s, c = !n && r > 1 && !Rt(t, e) && s.length < r || i; return { useSqueezeShape: c, uniformShape: c ? a : t, keptDims: o } } function lr(n, t) { const e = JSON.parse(JSON.stringify(n)); return e.shapeInfo.logicalShape = t, e } function ur(n, t) { return t.map(e => n[e]).join(", ") }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function PF(n, t, e, s) { const o = e.map((u, d) => { const h = { logicalShape: u.shape, texShape: u.isUniform ? null : u.texData.texShape, isUniform: u.isUniform, isPacked: u.isUniform ? !1 : u.texData.isPacked, flatOffset: null }; return u.texData != null && u.texData.slice != null && u.texData.slice.flatOffset > 0 && (h.flatOffset = u.texData.slice.flatOffset), { name: t.variableNames[d], shapeInfo: h } }), r = o.map(u => u.shapeInfo), i = { logicalShape: s.shape, texShape: s.texData.texShape, isUniform: !1, isPacked: s.texData.isPacked, flatOffset: null }, a = iF(o, i, t), c = MM(n.gl, a), l = n.createProgram(c); return A().get("ENGINE_COMPILE_ONLY") ? { program: t, fragmentShader: c, source: a, webGLProgram: l, inShapeInfos: r, outShapeInfo: i, uniformLocations: null, customUniformLocations: null, infLoc: null, nanLoc: null, inShapesLocations: null, inTexShapesLocations: null, outShapeLocation: null, outShapeStridesLocation: null, outTexShapeLocation: null } : Object.assign({ program: t, fragmentShader: c, source: a, webGLProgram: l, inShapeInfos: r, outShapeInfo: i }, Jy(n, t, l)) } function Jy(n, t, e) { const s = {}, o = {}, r = {}, i = []; let a, c, l, u = null, d = null; d = n.getUniformLocation(e, "NAN", !1), A().getNumber("WEBGL_VERSION") === 1 && (u = n.getUniformLocation(e, "INFINITY", !1)); const h = !1; for (let p = 0; p < t.variableNames.length; p++) { const f = t.variableNames[p]; s[f] = n.getUniformLocation(e, f, h), s[`offset${f}`] = n.getUniformLocation(e, `offset${f}`, h), t.enableShapeUniforms && (o[`${f}Shape`] = n.getUniformLocation(e, `${f}Shape`, h), r[`${f}TexShape`] = n.getUniformLocation(e, `${f}TexShape`, h)) } return t.enableShapeUniforms && (a = n.getUniformLocation(e, "outShape", h), l = n.getUniformLocation(e, "outShapeStrides", h), c = n.getUniformLocation(e, "outTexShape", h)), t.customUniforms && t.customUniforms.forEach((p, f) => { i[f] = n.getUniformLocation(e, p.name, h) }), { uniformLocations: s, customUniformLocations: i, infLoc: u, nanLoc: d, inShapesLocations: o, inTexShapesLocations: r, outShapeLocation: a, outShapeStridesLocation: l, outTexShapeLocation: c } } function jy(n, t) { if (n.length !== t.length) throw Error(`Binary was compiled with ${n.length} inputs, but was executed with ${t.length} inputs`); n.forEach((e, s) => { const o = e.logicalShape, r = t[s], i = r.shape; if (!Rt(o, i)) throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${i} must match`); if (e.isUniform && r.isUniform) return; const a = e.texShape, c = r.isUniform ? null : r.texData.texShape; if (!Rt(a, c)) throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${a} and ${c} must match`) }) } function KF(n, t, e, s, o) { t.program.enableShapeUniforms || (jy(t.inShapeInfos, e), jy([t.outShapeInfo], [s])); const r = s.texData.texture, i = s.texData.texShape; s.texData.isPacked ? n.setOutputPackedMatrixTexture(r.texture, i[0], i[1]) : n.setOutputMatrixTexture(r.texture, i[0], i[1]), n.setProgram(t.webGLProgram), A().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && n.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && n.gl.uniform1f(t.nanLoc, NaN), e.forEach((c, l) => { const u = t.program.variableNames[l], d = t.uniformLocations[u], h = t.uniformLocations[`offset${u}`], p = t.inShapesLocations[`${u}Shape`], f = t.inTexShapesLocations[`${u}TexShape`]; if (p) { const { uniformShape: m } = wp(t.program.packedInputs, c.shape, c.texData.texShape); switch (m.length) { case 1: n.gl.uniform1iv(p, new Int32Array(m)); break; case 2: n.gl.uniform2iv(p, new Int32Array(m)); break; case 3: n.gl.uniform3iv(p, new Int32Array(m)); break; case 4: n.gl.uniform4iv(p, new Int32Array(m)); break } } if (f && n.gl.uniform2i(f, c.texData.texShape[0], c.texData.texShape[1]), d != null) { if (c.isUniform) { if (Z(c.shape) < 2) n.gl.uniform1f(d, c.uniformValues[0]); else { let m = c.uniformValues; m instanceof Float32Array || (m = new Float32Array(m)), n.gl.uniform1fv(d, m) } return } c.texData.slice != null && h != null && n.gl.uniform1i(h, c.texData.slice.flatOffset), n.setInputMatrixTexture(c.texData.texture.texture, d, l) } }); const a = t.outShapeLocation; if (a) switch (s.shape.length) { case 1: n.gl.uniform1iv(a, new Int32Array(s.shape)); break; case 2: n.gl.uniform2iv(a, new Int32Array(s.shape)); break; case 3: n.gl.uniform3iv(a, new Int32Array(s.shape)); break; case 4: n.gl.uniform4iv(a, new Int32Array(s.shape)); break }if (t.outShapeStridesLocation) { const c = ct(s.shape); switch (s.shape.length) { case 2: n.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(c)); break; case 3: n.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(c)); break; case 4: n.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(c)); break } } t.outTexShapeLocation && n.gl.uniform2i(t.outTexShapeLocation, s.texData.texShape[0], s.texData.texShape[1]), t.program.customUniforms && o && t.program.customUniforms.forEach((c, l) => { const u = t.customUniformLocations[l], d = o[l]; if (c.type === "float") n.gl.uniform1fv(u, d); else if (c.type === "vec2") n.gl.uniform2fv(u, d); else if (c.type === "vec3") n.gl.uniform3fv(u, d); else if (c.type === "vec4") n.gl.uniform4fv(u, d); else if (c.type === "int") n.gl.uniform1iv(u, d); else if (c.type === "ivec2") n.gl.uniform2iv(u, d); else if (c.type === "ivec3") n.gl.uniform3iv(u, d); else if (c.type === "ivec4") n.gl.uniform4iv(u, d); else throw Error(`uniform type ${c.type} is not supported yet.`) }), n.executeProgram() } function ZF(n, t, e) { let s = ""; t.concat(e).forEach(i => { const a = i.texData != null && i.texData.slice != null && i.texData.slice.flatOffset > 0; if (n.enableShapeUniforms && !i.isUniform) { const c = i.texData.texShape, { useSqueezeShape: l, uniformShape: u, keptDims: d } = wp(n.packedInputs, i.shape, c); let h = "", p = "", f = ""; if (u.length === 1 && n.packedInputs) { const C = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)]; h = `${C[0] > 1}_${C[1] > 1}` } else if (u.length === 2 && !n.packedInputs) p = `${u[0] > 1}_${u[1] > 1}`; else if (u.length > 2 && !n.packedInputs) { const C = ct(u); f = `${C[0] === c[1]}_${C[C.length - 1] === c[1]}` } const m = i.shape.length, g = u.length === 2 && Rt(i.shape, c), b = Z(i.shape) === 1, x = Oo(i.shape, e.shape), I = !n.packedInputs && m === e.shape.length && Rt(c, e.texData.texShape), y = n.packedInputs || u.length > 2 ? "" : `${c[0] > 1}_${c[1] > 1}`; s += `${m}_${I}_${l ? d : ""}_${u.length}_${b}_${x}_${g}_${h}_${p}_${f}_${y}_${a}` } else { const c = i.isUniform ? "uniform" : i.texData.texShape; s += `${i.shape}_${c}_${a}` } }); const o = n.userCode; let r = n.constructor.name; return r += "_" + s + "_" + o + `${A().getNumber("WEBGL_VERSION")}`, r } function Ee(n) { return A().getBool("WEBGL_USE_SHAPES_UNIFORMS") && n <= 4 }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class BF {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outPackingScheme = Ji.DENSE, this.customUniforms = [{ name: "texShape", type: "ivec2" }]; const e = Le(); this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length), this.userCode = `
      ivec3 outCoordsFromFlatIndex(int index) {
        ${this.enableShapeUniforms ? wl(["r", "c", "d"], t) : Io(["r", "c", "d"], t)}
        return ivec3(r, c, d);
      }

      void main() {
        ivec2 resTexRC = ivec2(resultUV.yx * vec2(texShape[0], texShape[1]));
        int index = 4 * (resTexRC.x * texShape[1] + resTexRC.y);

        vec4 result = vec4(0.);

        for (int i=0; i<4; i++) {
          int flatIndex = index + i;
          ivec3 rc = outCoordsFromFlatIndex(flatIndex);
          result[i] = getA(rc.x, rc.y, rc.z);
        }

        ${e.output} = result;
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class HF {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outPackingScheme = Ji.DENSE, this.customUniforms = [{ name: "texShape", type: "ivec2" }]; const e = Le(); this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length), this.userCode = `
      ivec3 outCoordsFromFlatIndex(int index) {
        ${this.enableShapeUniforms ? wl(["r", "c", "d"], t) : Io(["r", "c", "d"], t)}
        return ivec3(r, c, d);
      }

      void main() {
        ivec2 resTexRC = ivec2(resultUV.yx * vec2(texShape[0], texShape[1]));
        int index = 4 * (resTexRC.x * texShape[1] + resTexRC.y);

        vec4 result = vec4(0.);

        for (int i=0; i<4; i++) {
          int flatIndex = index + i;
          ivec3 rc = outCoordsFromFlatIndex(flatIndex);
          result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));
        }

        ${e.output} = result;
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class _F {
        constructor(t) {
            this.variableNames = ["A"], this.outTexUsage = an.DOWNLOAD; const e = Le(); this.outputShape = t, this.userCode = `
      ${_y}

      void main() {
        float x = getAAtOutCoords();
        ${e.output} = encode_float(x);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class UF {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outTexUsage = an.DOWNLOAD; const e = Le(); this.outputShape = t, this.userCode = `
      ${_y}

      void main() {
        ivec3 coords = getOutputCoords();
        float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));
        ${e.output} = encode_float(x);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const YF = { R: 0, G: 1, B: 2, A: 3 }; class qy {
        constructor(t, e = !1, s = "RGBA") {
            this.variableNames = ["A"], this.customUniforms = [{ name: "texShape", type: "ivec2" }]; const o = Le(); this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length); let r = "result"; e && (r = "floor(result * 255. + 0.5)"); let i = ""; for (let a = 0; a < s.length; a++) {
                const c = s[a]; i += `
          if(offset == ${a}) {
            result = values[${YF[c]}];
          }`} this.userCode = `
      ${this.enableShapeUniforms ? Cp() : Ip(t)}

      void main() {
        ivec3 coords = getOutputCoords();
        int flatIndex = getFlatIndex(coords);
        float result = 0.;
        int offset = imod(flatIndex, ${s.length});

        flatIndex = idiv(flatIndex, ${s.length}, 1.);

        int r = flatIndex / texShape[1];
        if (r < texShape[0]) {
          int c = imod(flatIndex, texShape[1]);
          vec2 uv = (vec2(c, r) + halfCR) / vec2(texShape[1], texShape[0]);
          vec4 values = ${o.texture2D}(A, uv);
          ${i}
        }
        ${o.output} = vec4(${r}, 0., 0., 0.);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class QF {
        constructor(t, e = !1) {
            this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.customUniforms = [{ name: "texShape", type: "ivec2" }]; const s = Le(); this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length); let o = "", r = "result"; e && (r = "floor(result * 255. + 0.5)"); for (let i = 0; i <= 1; i++)for (let a = 0; a <= 1; a++) {
                const c = i * 2 + a; o += `
          localCoords = coords;
          if(localCoords[2] + ${a} < ${this.enableShapeUniforms ? "outShape[2]" : `${t[2]}`}) {
          localCoords[2] += ${a};
          if (localCoords[1] + ${i} < ${this.enableShapeUniforms ? "outShape[1]" : `${t[1]}`}) {
            localCoords[1] += ${i};

            flatIndex = getFlatIndex(localCoords);
            offset = imod(flatIndex, 4);

            flatIndex = idiv(flatIndex, 4, 1.);

            int r = flatIndex / texShape[1];
            int c = imod(flatIndex, texShape[1]);
            vec2 uv = (vec2(c, r) + halfCR) / vec2(texShape[1], texShape[0]);
            values = ${s.texture2D}(A, uv);

            if (offset == 0) {
              result[${c}] = values[0];
            } else if (offset == 1) {
              result[${c}] = values[1];
            } else if (offset == 2) {
              result[${c}] = values[2];
            } else {
              result[${c}] = values[3];
            }
          }
        }
        `} this.userCode = `
        ${this.enableShapeUniforms ? Cp() : Ip(t)}

        void main() {
          ivec3 coords = getOutputCoords();

          vec4 result = vec4(0.);
          int flatIndex, r, c, offset;
          ivec3 localCoords;
          vec2 uv;
          vec4 values;

          ${o}

          ${s.output} = ${r};
        }
    `}
    }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JF(n) {
        const t = Le(), e = `${t.version}
    precision highp float;
    ${t.attribute} vec3 clipSpacePos;
    ${t.attribute} vec2 uv;
    ${t.varyingVs} vec2 resultUV;

    void main() {
      gl_Position = vec4(clipSpacePos, 1);
      resultUV = uv;
    }`; return WM(n, e)
    } function jF(n) { const t = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]); return XM(n, t) } function qF(n) { const t = new Uint16Array([0, 1, 2, 2, 1, 3]); return AM(n, t) } function ta(n, t, e, s, o, r) { PM(t, e); const i = OM(n), a = n.TEXTURE_2D; return st(n, () => n.bindTexture(a, i)), st(n, () => n.texParameteri(a, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE)), st(n, () => n.texParameteri(a, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE)), st(n, () => n.texParameteri(a, n.TEXTURE_MIN_FILTER, n.NEAREST)), st(n, () => n.texParameteri(a, n.TEXTURE_MAG_FILTER, n.NEAREST)), A().getNumber("WEBGL_VERSION") === 1 ? st(n, () => n.texImage2D(a, 0, s, t, e, 0, o, r, null)) : st(n, () => n.texStorage2D(a, 1, s, t, e)), st(n, () => n.bindTexture(n.TEXTURE_2D, null)), { texture: i, texShape: [e, t] } } function t1(n) { return n.internalFormatFloat } function tV(n, t, e, s) { const [o, r] = ji(t, e); return ta(n, o, r, t1(s), s.textureFormatFloat, n.FLOAT) } function e1(n) { return n.internalFormatHalfFloat } function eV(n, t, e, s) { const [o, r] = ji(t, e); return ta(n, o, r, e1(s), s.textureFormatFloat, s.textureTypeHalfFloat) } function n1(n) { return n.downloadTextureFormat } function nV(n, t, e, s) { const [o, r] = ji(t, e); return ta(n, o, r, n1(s), n.RGBA, n.UNSIGNED_BYTE) } function s1(n) { return n.internalFormatPackedFloat } function sV(n, t, e, s) { const [o, r] = or(t, e); return ta(n, o, r, s1(s), n.RGBA, n.FLOAT) } function o1(n) { return n.internalFormatPackedHalfFloat } function oV(n, t, e, s) { const [o, r] = or(t, e); return ta(n, o, r, o1(s), n.RGBA, s.textureTypeHalfFloat) } function rV(n, t, e) { return st(n, () => n.bindBuffer(n.ARRAY_BUFFER, e)), Zy(n, t, "clipSpacePos", e, 3, 20, 0) && Zy(n, t, "uv", e, 2, 20, 12) } function iV(n, t, e, s, o, r) { st(n, () => n.bindTexture(n.TEXTURE_2D, t)); let i, a, c; o instanceof Uint8Array ? (i = new Uint8Array(e * s * 4), a = n.UNSIGNED_BYTE, c = n.RGBA) : (i = new Float32Array(e * s * 4), a = n.FLOAT, c = r.internalFormatPackedFloat), i.set(o), A().getNumber("WEBGL_VERSION") === 2 ? st(n, () => n.texSubImage2D(n.TEXTURE_2D, 0, 0, 0, e, s, n.RGBA, a, i)) : st(n, () => n.texImage2D(n.TEXTURE_2D, 0, c, e, s, 0, n.RGBA, a, i)), st(n, () => n.bindTexture(n.TEXTURE_2D, null)) } function aV(n, t, e) { st(n, () => n.bindTexture(n.TEXTURE_2D, t)), e.data instanceof Uint8Array ? A().getNumber("WEBGL_VERSION") === 2 ? st(n, () => n.texSubImage2D(n.TEXTURE_2D, 0, 0, 0, e.width, e.height, n.RGBA, n.UNSIGNED_BYTE, e.data)) : st(n, () => n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, e.width, e.height, 0, n.RGBA, n.UNSIGNED_BYTE, e.data)) : A().getNumber("WEBGL_VERSION") === 2 ? st(n, () => n.texSubImage2D(n.TEXTURE_2D, 0, 0, 0, n.RGBA, n.UNSIGNED_BYTE, e)) : st(n, () => n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, n.RGBA, n.UNSIGNED_BYTE, e)), st(n, () => n.bindTexture(n.TEXTURE_2D, null)) } function cV(n, t, e, s) { const o = n.createBuffer(); st(n, () => n.bindBuffer(n.PIXEL_PACK_BUFFER, o)); const a = 4 * 4 * t * e; return st(n, () => n.bufferData(n.PIXEL_PACK_BUFFER, a, n.STREAM_READ)), st(n, () => n.readPixels(0, 0, e, t, n.RGBA, n.FLOAT, 0)), st(n, () => n.bindBuffer(n.PIXEL_PACK_BUFFER, null)), o } function lV(n, t, e) { const s = n, o = new Float32Array(e); return s.bindBuffer(s.PIXEL_PACK_BUFFER, t), s.getBufferSubData(s.PIXEL_PACK_BUFFER, 0, o), s.bindBuffer(s.PIXEL_PACK_BUFFER, null), o } function uV(n, t, e, s) { const [o, r] = ji(t, e), i = 4, a = new Uint8Array(NM(t * e, i)); return st(n, () => n.readPixels(0, 0, o, r, s.downloadTextureFormat, n.UNSIGNED_BYTE, a)), new Float32Array(a.buffer) } function dV(n, t, e, s, o, r, i, a) { const c = n, l = new Float32Array(RM(r, i)); return c.bindBuffer(c.PIXEL_PACK_BUFFER, t), c.getBufferSubData(c.PIXEL_PACK_BUFFER, 0, l), c.bindBuffer(c.PIXEL_PACK_BUFFER, null), l } function hV(n, t, e) { const s = new Float32Array(t * e * 4); return st(n, () => n.readPixels(0, 0, e, t, n.RGBA, n.FLOAT, s)), s }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class vp { constructor(t) { this.outputTexture = null, this.program = null, this.disposed = !1, this.itemsToPoll = []; const e = A().getNumber("WEBGL_VERSION"); if (t != null ? (this.gl = t, SM(e, t)) : this.gl = Mn(e), t = this.gl, A().getNumber("WEBGL_VERSION") === 2) { const r = t; this.createVertexArray = () => st(r, () => r.createVertexArray()), this.bindVertexArray = i => st(r, () => r.bindVertexArray(i)), this.deleteVertexArray = i => st(r, () => r.deleteVertexArray(i)), this.getVertexArray = () => st(r, () => r.getParameter(r.VERTEX_ARRAY_BINDING)) } else if (t != null) { const r = t.getExtension("OES_vertex_array_object"); if (r == null) throw new Error("All WebGL1 implementations are expected to offer OES_vertex_array_object."); this.createVertexArray = () => st(t, () => r.createVertexArrayOES()), this.bindVertexArray = i => st(t, () => r.bindVertexArrayOES(i)), this.deleteVertexArray = i => st(t, () => r.deleteVertexArrayOES(i)), this.getVertexArray = () => st(t, () => t.getParameter(r.VERTEX_ARRAY_BINDING_OES)) } let s = "WEBGL_color_buffer_float"; const o = "EXT_color_buffer_half_float"; if (this.parallelCompilationExtension = this.gl.getExtension("KHR_parallel_shader_compile"), A().getNumber("WEBGL_VERSION") === 1) { const r = "OES_texture_float", i = "OES_texture_half_float"; if (this.textureFloatExtension = bl(this.gl, r), In(this.gl, i)) this.textureHalfFloatExtension = bl(this.gl, i); else if (A().get("WEBGL_FORCE_F16_TEXTURES")) throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true."); if (this.colorBufferFloatExtension = this.gl.getExtension(s), In(this.gl, o)) this.colorBufferHalfFloatExtension = bl(this.gl, o); else if (A().get("WEBGL_FORCE_F16_TEXTURES")) throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.") } else if (s = "EXT_color_buffer_float", In(this.gl, s)) this.colorBufferFloatExtension = this.gl.getExtension(s); else if (In(this.gl, o)) this.colorBufferHalfFloatExtension = this.gl.getExtension(o); else throw new Error("GL context does not support color renderable floats"); this.vertexBuffer = jF(this.gl), this.indexBuffer = qF(this.gl), this.framebuffer = KM(this.gl), this.textureConfig = fp(this.gl, this.textureHalfFloatExtension) } get debug() { return A().getBool("DEBUG") } dispose() { if (this.disposed) return; this.program != null && console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."), this.outputTexture != null && console.warn("Disposing a GPGPUContext that still has a bound output matrix texture.  This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing."); const t = this.gl; st(t, () => t.finish()), st(t, () => t.bindFramebuffer(t.FRAMEBUFFER, null)), st(t, () => t.deleteFramebuffer(this.framebuffer)), st(t, () => t.bindBuffer(t.ARRAY_BUFFER, null)), st(t, () => t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, null)), st(t, () => t.deleteBuffer(this.indexBuffer)), this.disposed = !0 } createFloat32MatrixTexture(t, e) { return this.throwIfDisposed(), tV(this.gl, t, e, this.textureConfig) } createFloat16MatrixTexture(t, e) { return this.throwIfDisposed(), eV(this.gl, t, e, this.textureConfig) } createUnsignedBytesMatrixTexture(t, e) { return this.throwIfDisposed(), nV(this.gl, t, e, this.textureConfig) } uploadPixelDataToTexture(t, e) { this.throwIfDisposed(), aV(this.gl, t, e) } uploadDenseMatrixToTexture(t, e, s, o) { this.throwIfDisposed(), iV(this.gl, t, e, s, o, this.textureConfig) } createFloat16PackedMatrixTexture(t, e) { return this.throwIfDisposed(), oV(this.gl, t, e, this.textureConfig) } createPackedMatrixTexture(t, e) { return this.throwIfDisposed(), sV(this.gl, t, e, this.textureConfig) } deleteMatrixTexture(t) { this.throwIfDisposed(), this.outputTexture === t && (By(this.gl, this.framebuffer), this.outputTexture = null), st(this.gl, () => this.gl.deleteTexture(t)) } downloadByteEncodedFloatMatrixFromOutputTexture(t, e, s) { return this.downloadMatrixDriver(t, () => uV(this.gl, e, s, this.textureConfig)) } downloadPackedMatrixFromBuffer(t, e, s, o, r, i) { return dV(this.gl, t, e, s, o, r, i, this.textureConfig) } downloadFloat32MatrixFromBuffer(t, e) { return lV(this.gl, t, e) } createBufferFromTexture(t, e, s) { this.bindTextureToFrameBuffer(t); const o = cV(this.gl, e, s, this.textureConfig); return this.unbindTextureToFrameBuffer(), o } createAndWaitForFence() { const t = this.createFence(this.gl); return this.pollFence(t) } createFence(t) { let e, s; if (A().getBool("WEBGL_FENCE_API_ENABLED")) { const o = t, r = o.fenceSync(o.SYNC_GPU_COMMANDS_COMPLETE, 0); t.flush(), s = () => { const i = o.clientWaitSync(r, 0, 0); return i === o.ALREADY_SIGNALED || i === o.CONDITION_SATISFIED }, e = r } else A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") > 0 ? (e = this.beginQuery(), this.endQuery(), s = () => this.isQueryAvailable(e, A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))) : s = () => !0; return { query: e, isFencePassed: s } } downloadMatrixFromPackedTexture(t, e, s) { return this.downloadMatrixDriver(t, () => hV(this.gl, e, s)) } createProgram(t) { this.throwIfDisposed(); const e = this.gl; this.vertexShader == null && (this.vertexShader = JF(e)); const s = VM(e); st(e, () => e.attachShader(s, this.vertexShader)), st(e, () => e.attachShader(s, t)), zM(e, s); let o; return o = Object.assign(s, { vao: this.createVertexArray() }), this.bindVertexArray(o.vao), st(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, this.indexBuffer)), console.assert(rV(e, o, this.vertexBuffer), "gpgpu_util.bindVertexProgramAttributeStreams not fully successful."), this.debug && mp(e, o), this.setProgram(o), o } deleteProgram(t) { this.throwIfDisposed(), t === this.program && (this.program = null), t != null && (st(this.gl, () => this.gl.deleteProgram(t)), this.deleteVertexArray(t.vao)) } setProgram(t) { this.throwIfDisposed(), this.program = t, this.program != null && (this.bindVertexArray(this.program.vao), this.debug && mp(this.gl, this.program)), st(this.gl, () => this.gl.useProgram(t)) } getUniformLocation(t, e, s = !0) { return this.throwIfDisposed(), s ? BM(this.gl, t, e) : HM(this.gl, t, e) } getAttributeLocation(t, e) { return this.throwIfDisposed(), st(this.gl, () => this.gl.getAttribLocation(t, e)) } getUniformLocationNoThrow(t, e) { return this.throwIfDisposed(), this.gl.getUniformLocation(t, e) } setInputMatrixTexture(t, e, s) { this.throwIfDisposed(), this.throwIfNoProgram(), _M(this.gl, t, e, s) } setOutputMatrixTexture(t, e, s) { this.setOutputMatrixTextureDriver(t, s, e) } setOutputPackedMatrixTexture(t, e, s) { this.throwIfDisposed(); const [o, r] = or(e, s); this.setOutputMatrixTextureDriver(t, o, r) } setOutputMatrixWriteRegion(t, e, s, o) { this.setOutputMatrixWriteRegionDriver(s, t, o, e) } setOutputPackedMatrixWriteRegion(t, e, s, o) { throw new Error("setOutputPackedMatrixWriteRegion not implemented.") } debugValidate() { this.program != null && mp(this.gl, this.program), xl(this.gl) } executeProgram() { this.throwIfDisposed(), this.throwIfNoProgram(); const t = this.gl; if (this.debug) { const e = this.getVertexArray(); console.assert(e === this.program.vao, "VAO changed between setProgram and executeProgram!"), this.debugValidate() } st(t, () => t.drawElements(t.TRIANGLES, 6, t.UNSIGNED_SHORT, 0)) } blockUntilAllProgramsCompleted() { this.throwIfDisposed(), st(this.gl, () => this.gl.finish()) } getQueryTimerExtension() { return this.disjointQueryTimerExtension == null && (this.disjointQueryTimerExtension = bl(this.gl, A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2 ? "EXT_disjoint_timer_query_webgl2" : "EXT_disjoint_timer_query")), this.disjointQueryTimerExtension } getQueryTimerExtensionWebGL2() { return this.getQueryTimerExtension() } getQueryTimerExtensionWebGL1() { return this.getQueryTimerExtension() } beginQuery() { if (A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2) { const s = this.gl, o = this.getQueryTimerExtensionWebGL2(), r = s.createQuery(); return s.beginQuery(o.TIME_ELAPSED_EXT, r), r } const t = this.getQueryTimerExtensionWebGL1(), e = t.createQueryEXT(); return t.beginQueryEXT(t.TIME_ELAPSED_EXT, e), e } endQuery() { if (A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION") === 2) { const e = this.gl, s = this.getQueryTimerExtensionWebGL2(); e.endQuery(s.TIME_ELAPSED_EXT); return } const t = this.getQueryTimerExtensionWebGL1(); t.endQueryEXT(t.TIME_ELAPSED_EXT) } async waitForQueryAndGetTime(t) { return await nf(() => this.disposed || this.isQueryAvailable(t, A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))), this.getQueryTime(t, A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")) } getQueryTime(t, e) { if (e === 0) return null; if (e === 2) { const s = this.gl; return s.getQueryParameter(t, s.QUERY_RESULT) / 1e6 } else { const s = this.getQueryTimerExtensionWebGL1(); return s.getQueryObjectEXT(t, s.QUERY_RESULT_EXT) / 1e6 } } isQueryAvailable(t, e) { if (e === 0) return !0; if (e === 2) { const s = this.gl, o = this.getQueryTimerExtensionWebGL2(), r = s.getQueryParameter(t, s.QUERY_RESULT_AVAILABLE); return this.disjoint == null && (this.disjoint = this.gl.getParameter(o.GPU_DISJOINT_EXT)), r && !this.disjoint } else { const s = this.getQueryTimerExtensionWebGL1(), o = s.getQueryObjectEXT(t, s.QUERY_RESULT_AVAILABLE_EXT); return this.disjoint == null && (this.disjoint = this.gl.getParameter(s.GPU_DISJOINT_EXT)), o && !this.disjoint } } pollFence(t) { return new Promise(e => { this.addItemToPoll(() => t.isFencePassed(), () => e()) }) } pollItems() { const t = pV(this.itemsToPoll.map(e => e.isDoneFn)); for (let e = 0; e <= t; ++e) { const { resolveFn: s } = this.itemsToPoll[e]; s() } this.itemsToPoll = this.itemsToPoll.slice(t + 1) } addItemToPoll(t, e) { if (this.itemsToPoll.push({ isDoneFn: t, resolveFn: e }), this.itemsToPoll.length > 1) return; let s; "setTimeoutCustom" in A().platform && (s = A().platform.setTimeoutCustom.bind(A().platform)), nf(() => (this.pollItems(), this.itemsToPoll.length === 0), () => 0, null, s) } bindTextureToFrameBuffer(t) { this.throwIfDisposed(), gp(this.gl, t, this.framebuffer), this.debug && xl(this.gl) } unbindTextureToFrameBuffer() { this.outputTexture != null ? (gp(this.gl, this.outputTexture, this.framebuffer), this.debug && xl(this.gl)) : By(this.gl, this.framebuffer) } downloadMatrixDriver(t, e) { this.bindTextureToFrameBuffer(t); const s = e(); return this.unbindTextureToFrameBuffer(), s } setOutputMatrixTextureDriver(t, e, s) { this.throwIfDisposed(); const o = this.gl; gp(o, t, this.framebuffer), this.debug && xl(o), this.outputTexture = t, st(o, () => o.viewport(0, 0, e, s)), st(o, () => o.scissor(0, 0, e, s)) } setOutputMatrixWriteRegionDriver(t, e, s, o) { this.throwIfDisposed(), st(this.gl, () => this.gl.scissor(t, e, s, o)) } throwIfDisposed() { if (this.disposed) throw new Error("Attempted to use disposed GPGPUContext.") } throwIfNoProgram() { if (this.program == null) throw new Error("No GPU program is currently set.") } } function pV(n) { let t = 0; for (; t < n.length && n[t](); ++t); return t - 1 }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const { addImpl: fV, bincountImpl: r1, bincountReduceImpl: mV, castImpl: gV, ceilImpl: bV, concatImpl: xV, equalImpl: yV, expImpl: IV, expm1Impl: CV, floorImpl: wV, gatherNdImpl: vV, gatherV2Impl: SV, greaterImpl: kV, greaterEqualImpl: TV, lessImpl: NV, lessEqualImpl: RV, linSpaceImpl: $V, logImpl: GV, maxImpl: LV, maximumImpl: EV, minimumImpl: DV, multiplyImpl: WV, negImpl: MV, notEqualImpl: FV, prodImpl: VV, raggedGatherImpl: zV, raggedRangeImpl: XV, raggedTensorToTensorImpl: AV, rangeImpl: OV, rsqrtImpl: PV, scatterImpl: KV, sigmoidImpl: ZV, simpleAbsImpl: i1, sliceImpl: BV, sparseFillEmptyRowsImpl: HV, sparseReshapeImpl: _V, sparseSegmentReductionImpl: a1, sqrtImpl: UV, stridedSliceImpl: YV, stringNGramsImpl: QV, stringSplitImpl: JV, stringToHashBucketFastImpl: jV, subImpl: qV, tileImpl: tz, topKImpl: ez, transposeImpl: Sp, uniqueImpl: nz } = uL;/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function c1(n, t) { return ["x", "y", "z", "w", "u", "v"].slice(0, t).map(e => `${n}.${e}`) } function De(n, t) { return t === 1 ? [n] : c1(n, t) } function sz(n, t) { if (n === 1) return "rc"; let e = ""; for (let s = 0; s < n; s++)e += t[s], s < n - 1 && (e += ","); return e }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class oz {
        constructor(t) {
            if (this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0, this.outputShape = t, this.rank = t.length, this.enableShapeUniforms = Ee(this.outputShape.length), this.rank === 0) this.userCode = `
        void main() {
          setOutput(vec4(getA(), 0., 0., 0.));
        }
      `; else {
                const e = De("rc", this.rank), s = Xt(this.rank), o = this.getOutOfBoundsCondition(e), r = this.getSetup(e), i = this.getOutput(e); this.userCode = `
        void main() {
          ${s} rc = getOutputCoords();

          if(${o}) {
            setOutput(vec4(0));
          } else {
            ${r}

            setOutput(vec4(${i}));
          }
        }
      `}
        } getSourceCoordsArr(t) { const e = []; for (let s = 0; s <= 1; s++)for (let o = 0; o <= 1; o++) { let r = `${s === 0 ? "r" : "rp1"}, ${o === 0 ? "c" : "cp1"}`; for (let i = 2; i < this.rank; i++)r = `${t[t.length - 1 - i]},` + r; e.push(r) } return e } getOutOfBoundsCondition(t) { if (this.rank === 1) return `rc > ${this.enableShapeUniforms ? "outShape" : this.outputShape[0]}`; let e = ""; for (let s = this.rank - 2; s < this.rank; s++)e += `${t[s]} >= ${this.enableShapeUniforms ? `outShape[${s}]` : this.outputShape[s]}`, s < this.rank - 1 && (e += "||"); return e } getSetup(t) {
            if (this.rank === 1) return ""; const e = t.slice(-2), s = this.enableShapeUniforms ? `outShape[${this.rank} - 1]` : this.outputShape[this.rank - 1], o = this.enableShapeUniforms ? `outShape[${this.rank} - 2]` : this.outputShape[this.rank - 2]; return `
      int r = ${e[0]};
      int c = ${e[1]};
      int rp1 = r + 1;
      int cp1 = c + 1;

      bool cEdge = cp1 >= ${s};
      bool rEdge = rp1 >= ${o};
    `} getOutput(t) {
            const e = this.getSourceCoordsArr(t); return this.rank === 1 ? `getA(rc), (rc + 1 >= ${this.enableShapeUniforms ? "outShape" : this.outputShape[0]} ? 0. : getA(rc + 1)), 0, 0` : `getA(${e[0]}),
            cEdge ? 0. : getA(${e[1]}),
            rEdge ? 0. : getA(${e[2]}),
            rEdge || cEdge ? 0. : getA(${e[3]})`
        }
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class l1 {
        constructor(t, e) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec3" }], this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length); let s = ""; for (let o = 0; o < 4; o++) {
                let r = "thisRC = rc;"; o % 2 === 1 && (r += "thisRC.z += 1;"), o > 1 && (r += "thisRC.y += 1;"), s += `
        ${r}
        ${o > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : ""}
          int flatIndex = getFlatIndex(thisRC);

          ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
          vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));

          result[${o}] =
            getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
        ${o > 0 ? "}" : ""}
      `} this.userCode = `
      ${rz(e, this.enableShapeUniforms)}
      ${this.enableShapeUniforms ? Cp() : Ip(t)}

      void main() {
        ivec3 rc = getOutputCoords();

        vec4 result = vec4(0.);

        ivec3 thisRC;
        int rows = ${this.enableShapeUniforms ? "outShape[1]" : t[1]};
        int cols = ${this.enableShapeUniforms ? "outShape[2]" : t[2]};

        ${s}

        setOutput(result);
      }
    `}
    } function rz(n, t) {
        return `
    ivec3 inputCoordsFromReshapedOutCoords(int index) {
      ${t ? rF(["r", "c", "d"], "inputShape") : Io(["r", "c", "d"], n)}
      return ivec3(r, c, d);
    }
  `}/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class iz { constructor(t) { this.gpgpu = t, this.numUsedTextures = 0, this.numFreeTextures = 0, this._numBytesAllocated = 0, this._numBytesFree = 0, this.freeTextures = {}, this.logEnabled = !1, this.usedTextures = {} } acquireTexture(t, e, s) { const o = d1(e, s), r = h1(t, o, s); r in this.freeTextures || (this.freeTextures[r] = []), r in this.usedTextures || (this.usedTextures[r] = []); const i = u1(t, o, this.gpgpu.gl, this.gpgpu.textureConfig, s); if (this.freeTextures[r].length > 0) { this.numFreeTextures--, this.numUsedTextures++, this._numBytesFree -= i, this.log(); const c = this.freeTextures[r].shift(); return this.usedTextures[r].push(c), c } let a; return o === Ce.PACKED_2X2_FLOAT32 ? a = this.gpgpu.createPackedMatrixTexture(t[0], t[1]) : o === Ce.PACKED_2X2_FLOAT16 ? a = this.gpgpu.createFloat16PackedMatrixTexture(t[0], t[1]) : o === Ce.UNPACKED_FLOAT32 ? a = this.gpgpu.createFloat32MatrixTexture(t[0], t[1]) : o === Ce.UNPACKED_FLOAT16 ? a = this.gpgpu.createFloat16MatrixTexture(t[0], t[1]) : o === Ce.PACKED_4X1_UNSIGNED_BYTE && (a = this.gpgpu.createUnsignedBytesMatrixTexture(t[0], t[1])), this.usedTextures[r].push(a), this.numUsedTextures++, this._numBytesAllocated += i, this.log(), a } releaseTexture(t, e, s, o) { if (this.freeTextures == null) return; const r = d1(s, o), i = h1(e, r, o); i in this.freeTextures || (this.freeTextures[i] = []); const a = u1(e, r, this.gpgpu.gl, this.gpgpu.textureConfig, o), c = A().get("WEBGL_DELETE_TEXTURE_THRESHOLD"); c !== -1 && this._numBytesAllocated > c ? (this.gpgpu.deleteMatrixTexture(t.texture), this._numBytesAllocated -= a) : (this.freeTextures[i].push(t), this.numFreeTextures++, this._numBytesFree += a), this.numUsedTextures--; const l = this.usedTextures[i], u = l.indexOf(t); if (u < 0) throw new Error("Cannot release a texture that was never provided by this texture manager"); l.splice(u, 1), this.log() } log() { if (!this.logEnabled) return; const t = this.numFreeTextures + this.numUsedTextures; console.log("Free/Used", `${this.numFreeTextures} / ${this.numUsedTextures}`, `(${t})`); const e = this._numBytesFree / this._numBytesAllocated; console.log(`Bytes allocated: ${this._numBytesAllocated}`), console.log(`Bytes unused: ${this._numBytesFree} (${Math.round(100 * e)}%)`) } get numBytesAllocated() { return this._numBytesAllocated } get numBytesFree() { return this._numBytesFree } getNumUsedTextures() { return this.numUsedTextures } getNumFreeTextures() { return this.numFreeTextures } dispose() { if (this.freeTextures != null) { for (const t in this.freeTextures) this.freeTextures[t].forEach(e => { this.gpgpu.deleteMatrixTexture(e.texture) }); for (const t in this.usedTextures) this.usedTextures[t].forEach(e => { this.gpgpu.deleteMatrixTexture(e.texture) }); this.freeTextures = null, this.usedTextures = null, this.numUsedTextures = 0, this.numFreeTextures = 0, this._numBytesAllocated = 0, this._numBytesFree = 0 } } } function az(n, t) { const e = n; if (t === e.R32F) return 4; if (t === e.R16F) return 2; if (t === e.RGBA32F) return 16; if (t === n.RGBA) return 16; if (t === e.RGBA16F) return 8; if (t === e.RGBA8) return 4; throw new Error(`Unknown internal format ${t}`) } function u1(n, t, e, s, o) { const r = cz(t, s); let i; if (o) { const [c, l] = or(n[0], n[1]); i = c * l } else { const [c, l] = ji(n[0], n[1]); i = c * l } const a = az(e, r); return i * a } function cz(n, t) { switch (n) { case Ce.PACKED_2X2_FLOAT32: return s1(t); case Ce.PACKED_2X2_FLOAT16: return o1(t); case Ce.UNPACKED_FLOAT32: return t1(t); case Ce.UNPACKED_FLOAT16: return e1(t); case Ce.PACKED_4X1_UNSIGNED_BYTE: return n1(t); default: throw new Error(`Unknown physical texture type ${n}`) } } function lz(n) { return A().getBool("WEBGL_RENDER_FLOAT32_ENABLED") ? n ? Ce.PACKED_2X2_FLOAT32 : Ce.UNPACKED_FLOAT32 : n ? Ce.PACKED_2X2_FLOAT16 : Ce.UNPACKED_FLOAT16 } function d1(n, t) { if (n === an.UPLOAD) return Ce.PACKED_2X2_FLOAT32; if (n === an.RENDER || n == null) return lz(t); if (n === an.DOWNLOAD || n === an.PIXELS) return Ce.PACKED_4X1_UNSIGNED_BYTE; throw new Error(`Unknown logical texture type ${n}`) } function h1(n, t, e) { return `${n[0]}_${n[1]}_${t}_${e}` }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Yn {
        constructor(t, e) {
            this.variableNames = ["A"], this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length), this.userCode = `
      float unaryOperation(float x) {
        ${e}
      }

      void main() {
        float x = getAAtOutCoords();
        float y = unaryOperation(x);

        setOutput(y);
      }
    `}
    } const Cn = "if (isnan(x)) return x;", uz = "return x;", p1 = "return abs(x);", dz = "return (x >= 0.0) ? x : (exp(x) - 1.0);", hz = Cn + `
  return (x < 0.0) ? 0.0 : x;
`, pz = Cn + `
  return (x < 0.0) ? 0.0 : min(6.0, x);
`, Es = "return x;", fz = "return 1.0 / (1.0 + exp(-1.0 * x));";/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const mz = "return x;", gz = `
  vec4 result;

  result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
  result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
  result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
  result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);

  return result;
`, bz = `
  vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`, xz = `
  vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`, yz = "return 1.0 / (1.0 + exp(-1.0 * x));"; class Ds {
        constructor(t, e) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length), this.userCode = `
      vec4 unaryOperation(vec4 x) {
        ${e}
      }

      void main() {
        vec4 x = getAAtOutCoords();
        vec4 y = unaryOperation(x);

        setOutput(y);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Iz {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !1, this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length); const e = t.length, s = De("rc", e), o = Xt(e), r = sz(e, s), i = s.slice(-2), a = e <= 1 ? "rc" : `vec2(${i.join(",")})`; this.userCode = `
      void main() {
        ${o} rc = getOutputCoords();
        vec4 packedInput = getA(${r});

        setOutput(getChannel(packedInput, ${a}));
      }
    `}
    }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Cz = Um, wz = 1e-7, vz = 1e-4, vl = {}; function Sz(n) { return n in vl || (vl[n] = {}), vl[n] } const kz = A().getNumber("CPU_HANDOFF_SIZE_THRESHOLD"), Tz = 600; function Nz() { return A().global.screen == null ? 1024 : A().global.screen.height * A().global.screen.width * window.devicePixelRatio * Tz / 1024 / 1024 } class Sl extends Al { constructor(t) { if (super(), this.pendingRead = new WeakMap, this.pendingDisposal = new WeakSet, this.dataRefCount = new WeakMap, this.numBytesInGPU = 0, this.uploadWaitMs = 0, this.downloadWaitMs = 0, this.lastGlFlushTime = 0, this.warnedAboutMemory = !1, this.pendingDeletes = 0, this.disposed = !1, !A().getBool("HAS_WEBGL")) throw new Error("WebGL is not supported on this device"); let e; if (t != null) { if (t instanceof vp) e = t; else { const s = Mn(A().getNumber("WEBGL_VERSION"), t); e = new vp(s) } this.binaryCache = {}, this.gpgpuCreatedLocally = !1 } else { const s = Mn(A().getNumber("WEBGL_VERSION")); e = new vp(s), this.binaryCache = Sz(A().getNumber("WEBGL_VERSION")), this.gpgpuCreatedLocally = !0 } this.gpgpu = e, this.canvas = this.gpgpu.gl.canvas, this.textureManager = new iz(this.gpgpu), this.numMBBeforeWarning = Nz(), this.texData = new ef(this, Ft()) } nextDataId() { return Sl.nextDataId++ } numDataIds() { return this.texData.numDataIds() - this.pendingDeletes } writeTexture(t, e, s, o, r, i) { const a = this.makeTensorInfo(e, s), c = this.texData.get(a.dataId); c.isPacked = !1, c.texture = { texture: t, texShape: [o, r] }, c.texShape = [o, r]; const l = yl(e), u = new qy(l, !1, i), d = this.runWebGLProgram(u, [a], s, [[o, r]]); return d.shape = e, c.texture = null, this.disposeIntermediateTensorInfo(a), d.dataId } write(t, e, s) { if ((A().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS") || A().getBool("DEBUG")) && this.checkNumericalProblems(t), s === "complex64" && t != null) throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag)."); const o = { id: this.nextDataId() }; return this.texData.set(o, { shape: e, dtype: s, values: t, usage: an.UPLOAD, refCount: 1 }), o } refCount(t) { return this.texData.has(t) ? this.texData.get(t).refCount : 0 } incRef(t) { const e = this.texData.get(t); e.refCount++ } decRef(t) { if (this.texData.has(t)) { const e = this.texData.get(t); e.refCount-- } } move(t, e, s, o, r) { if (A().getBool("DEBUG") && this.checkNumericalProblems(e), o === "complex64") throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag)."); this.texData.set(t, { shape: s, dtype: o, values: e, usage: an.UPLOAD, refCount: r }) } disposeIntermediateTensorInfo(t) { this.disposeData(t.dataId) } readSync(t) { const e = this.texData.get(t), { values: s, dtype: o, complexTensorInfos: r, slice: i, shape: a, isPacked: c } = e; if (i != null) { let h; c ? h = new Ds(a, Es) : h = new Yn(a, Es); const p = this.runWebGLProgram(h, [{ dataId: t, shape: a, dtype: o }], o), f = this.readSync(p.dataId); return this.disposeIntermediateTensorInfo(p), f } if (s != null) return this.convertAndCacheOnCPU(t); if (o === "string") return s; const l = this.activeTimers != null; let u; l && (u = Me()); let d; if (o === "complex64") { const h = this.readSync(r.real.dataId), p = this.readSync(r.imag.dataId); d = rs(h, p) } else d = this.getValuesFromTexture(t); return l && (this.downloadWaitMs += Me() - u), this.convertAndCacheOnCPU(t, d) } async read(t) { if (this.pendingRead.has(t)) { const f = this.pendingRead.get(t); return new Promise(m => f.push(m)) } const e = this.texData.get(t), { values: s, shape: o, slice: r, dtype: i, complexTensorInfos: a, isPacked: c } = e; if (r != null) { let f; c ? f = new Ds(o, Es) : f = new Yn(o, Es); const m = this.runWebGLProgram(f, [{ dataId: t, shape: o, dtype: i }], i), g = this.read(m.dataId); return this.disposeIntermediateTensorInfo(m), g } if (s != null) return this.convertAndCacheOnCPU(t); if (A().getBool("DEBUG") && !A().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED") && A().getNumber("WEBGL_VERSION") === 2) throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported."); let l = null, u; if (i !== "complex64" && A().get("WEBGL_BUFFER_SUPPORTED")) { u = this.decode(t); const f = this.texData.get(u.dataId); l = this.gpgpu.createBufferFromTexture(f.texture.texture, ...gl(o)) } this.pendingRead.set(t, []), i !== "complex64" && await this.gpgpu.createAndWaitForFence(); let d; if (i === "complex64") { const f = await Promise.all([this.read(a.real.dataId), this.read(a.imag.dataId)]), m = f[0], g = f[1]; d = rs(m, g) } else if (l == null) d = this.getValuesFromTexture(t); else { const f = Z(o); d = this.gpgpu.downloadFloat32MatrixFromBuffer(l, f) } if (u != null && this.disposeIntermediateTensorInfo(u), l != null) { const f = this.gpgpu.gl; st(f, () => f.deleteBuffer(l)) } const h = this.convertAndCacheOnCPU(t, d), p = this.pendingRead.get(t); return this.pendingRead.delete(t), p.forEach(f => f(h)), this.pendingDisposal.has(t) && (this.pendingDisposal.delete(t), this.disposeData(t) && Ft().removeDataId(t, this), this.pendingDeletes--), h } readToGPU(t, e = {}) { const s = this.texData.get(t), { values: o, shape: r, slice: i, dtype: a, isPacked: c, texture: l } = s; if (a === "complex64") throw new Error("Does not support reading texture for complex64 dtype."); if (i != null) { let p; c ? p = new Ds(r, Es) : p = new Yn(r, Es); const f = this.runWebGLProgram(p, [{ dataId: t, shape: r, dtype: a }], a), m = this.readToGPU(f, e); return this.disposeIntermediateTensorInfo(f), m } if (l == null) throw o != null ? new Error("Data is not on GPU but on CPU.") : new Error("There is no data on GPU or CPU."); const u = this.decode(t, e.customTexShape), d = Ft().makeTensorFromTensorInfo(u), h = this.texData.get(u.dataId); return Object.assign({ tensorRef: d }, h.texture) } bufferSync(t) { const e = this.readSync(t.dataId); if (t.dtype === "string") try { const s = e.map(o => ms(o)); return Ct(t.shape, t.dtype, s) } catch { throw new Error("Failed to decode encoded string bytes into utf-8") } return Ct(t.shape, t.dtype, e) } checkNumericalProblems(t) { if (t != null) for (let e = 0; e < t.length; e++) { const s = t[e]; if (!EM(s)) throw A().getBool("WEBGL_RENDER_FLOAT32_CAPABLE") ? Error(`The value ${s} cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'`) : Error(`The value ${s} cannot be represented on this device.`) } } getValuesFromTexture(t) { const { shape: e, dtype: s, isPacked: o } = this.texData.get(t), r = Z(e); if (A().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")) { const h = this.decode(t), p = this.texData.get(h.dataId), f = this.gpgpu.downloadMatrixFromPackedTexture(p.texture.texture, ...gl(e)).subarray(0, r); return this.disposeIntermediateTensorInfo(h), f } const i = A().getBool("WEBGL_PACK") && o === !0, a = i ? yl(e) : e, c = i ? new UF(a) : new _F(a), l = this.runWebGLProgram(c, [{ shape: a, dtype: s, dataId: t }], "float32"), u = this.texData.get(l.dataId), d = this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(u.texture.texture, u.texShape[0], u.texShape[1]).subarray(0, r); return this.disposeIntermediateTensorInfo(l), d } timerAvailable() { return A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 } time(t) { const e = this.activeTimers, s = []; let o = !1; this.programTimersStack == null ? (this.programTimersStack = s, o = !0) : this.activeTimers.push(s), this.activeTimers = s, t(); const r = Hs(this.activeTimers.map(c => c.query)).filter(c => c != null), i = Hs(this.activeTimers.map(c => c.name)).filter(c => c != null); this.activeTimers = e, o && (this.programTimersStack = null); const a = { uploadWaitMs: this.uploadWaitMs, downloadWaitMs: this.downloadWaitMs, kernelMs: null, wallMs: null }; return (async () => { if (A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0) { const c = await Promise.all(r); a.kernelMs = VI(c), a.getExtraProfileInfo = () => c.map((l, u) => ({ name: i[u], ms: l })).map(l => `${l.name}: ${l.ms}`).join(", ") } else a.kernelMs = { error: "WebGL query timers are not supported in this environment." }; return this.uploadWaitMs = 0, this.downloadWaitMs = 0, a })() } memory() { return { unreliable: !1, numBytesInGPU: this.numBytesInGPU, numBytesInGPUAllocated: this.textureManager.numBytesAllocated, numBytesInGPUFree: this.textureManager.numBytesFree } } startTimer() { return A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? this.gpgpu.beginQuery() : { startMs: Me(), endMs: null } } endTimer(t) { return A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0 ? (this.gpgpu.endQuery(), t) : (t.endMs = Me(), t) } async getQueryTime(t) { if (A().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE") > 0) return this.gpgpu.waitForQueryAndGetTime(t); const e = t; return e.endMs - e.startMs } disposeData(t, e = !1) { if (this.pendingDisposal.has(t)) return !1; if (!this.texData.has(t)) return !0; if (e ? this.texData.get(t).refCount = 0 : this.texData.get(t).refCount--, !e && this.texData.get(t).refCount > 0) return !1; if (this.pendingRead.has(t)) return this.pendingDisposal.add(t), this.pendingDeletes++, !1; this.releaseGPUData(t); const { complexTensorInfos: s } = this.texData.get(t); return s != null && (this.disposeData(s.real.dataId, e), this.disposeData(s.imag.dataId, e)), this.texData.delete(t), !0 } releaseGPUData(t) { const { texture: e, dtype: s, texShape: o, usage: r, isPacked: i, slice: a } = this.texData.get(t), c = a && a.origDataId || t, l = this.dataRefCount.get(c); l > 1 ? this.dataRefCount.set(c, l - 1) : (this.dataRefCount.delete(c), e != null && (this.numBytesInGPU -= this.computeBytes(o, s), this.textureManager.releaseTexture(e, o, r, i))); const u = this.texData.get(t); u.texture = null, u.texShape = null, u.isPacked = !1, u.slice = null } getTexture(t) { return this.uploadToGPU(t), this.texData.get(t).texture.texture } getDataInfo(t) { return this.texData.get(t) } shouldExecuteOnCPU(t, e = kz) { return A().getBool("WEBGL_CPU_FORWARD") && t.every(s => this.texData.get(s.dataId).texture == null && Z(s.shape) < e) } getGPGPUContext() { return this.gpgpu } where(t) { Qe("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead"); const e = t.dataSync(); return Cz(t.shape, e) } packedUnaryOp(t, e, s) { const o = new Ds(t.shape, e), r = this.compileAndRun(o, [t], s); return Ft().makeTensorFromTensorInfo(r) } abs(t) { if (this.shouldExecuteOnCPU([t]) && t.dtype !== "complex64") { const o = i1(this.texData.get(t.dataId).values); return this.makeOutput(t.shape, t.dtype, o) } if (A().getBool("WEBGL_PACK_UNARY_OPERATIONS")) return this.packedUnaryOp(t, p1, t.dtype); const e = new Yn(t.shape, p1), s = this.compileAndRun(e, [t]); return Ft().makeTensorFromTensorInfo(s) } makeTensorInfo(t, e, s) { let o; if (e === "string" && s != null && s.length > 0 && br(s[0])) { const r = s.map(i => fs(i)); o = this.write(r, t, e) } else o = this.write(s, t, e); return this.texData.get(o).usage = null, { dataId: o, shape: t, dtype: e } } makeOutput(t, e, s) { return Ft().makeTensorFromTensorInfo(this.makeTensorInfo(t, e, s), this) } unpackTensor(t) { const e = new Iz(t.shape); return this.runWebGLProgram(e, [t], t.dtype) } packTensor(t) { const e = new oz(t.shape), s = !0; return this.runWebGLProgram(e, [t], t.dtype, null, s) } packedReshape(t, e) { const s = [rr(t.shape), ...ir(t.shape)], o = { dtype: t.dtype, shape: s, dataId: t.dataId }, r = [rr(e), ...ir(e)], i = new l1(r, s), a = !0, c = [s], l = this.runWebGLProgram(i, [o], t.dtype, c, a); return { dataId: l.dataId, shape: e, dtype: l.dtype } } decode(t, e) { const s = this.texData.get(t), { isPacked: o, shape: r, dtype: i } = s; if (e != null) { const h = Z(r), p = e[0] * e[1] * 4; v(h <= p, () => "customTexShape is too small. Row * Column * 4 should be equal or larger than the size of the tensor data.") } const a = yl(r); let c; o ? c = new HF(a) : c = new BF(a); const l = !0, u = [e ?? gl(a)], d = this.runWebGLProgram(c, [{ shape: a, dtype: i, dataId: t }], i, u, l, e); return { dtype: i, shape: r, dataId: d.dataId } } runWebGLProgram(t, e, s, o, r = !1, i) { const a = this.makeTensorInfo(t.outputShape, s), c = this.texData.get(a.dataId); if (t.packedOutput && (c.isPacked = !0), t.outPackingScheme === Ji.DENSE) { const b = i ?? gl(t.outputShape); c.texShape = b.map(x => x * 2) } if (t.outTexUsage != null && (c.usage = t.outTexUsage), Z(a.shape) === 0) return c.values = xe(a.dtype, 0), a; const l = [], u = e.map(b => { if (b.dtype === "complex64") throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts."); let x = this.texData.get(b.dataId); if (x.texture == null) { if (!t.packedInputs && Z(b.shape) <= A().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM")) return { shape: b.shape, texData: null, isUniform: !0, uniformValues: x.values }; t.packedInputs && (x.isPacked = !0, x.shape = b.shape) } if (this.uploadToGPU(b.dataId), !!x.isPacked != !!t.packedInputs) b = x.isPacked ? this.unpackTensor(b) : this.packTensor(b), l.push(b), x = this.texData.get(b.dataId); else if (x.isPacked && !Cl(x.shape, b.shape)) { const I = b, y = b.shape; b.shape = x.shape, b = this.packedReshape(b, y), l.push(b), x = this.texData.get(b.dataId), I.shape = y } return { shape: b.shape, texData: x, isUniform: !1 } }); this.uploadToGPU(a.dataId); const d = { shape: a.shape, texData: c, isUniform: !1 }, h = ZF(t, u, d), p = this.getAndSaveBinary(h, () => PF(this.gpgpu, t, u, d)), f = this.activeTimers != null; let m; f && (m = this.startTimer()), A().get("ENGINE_COMPILE_ONLY") || KF(this.gpgpu, p, u, d, o), l.forEach(b => this.disposeIntermediateTensorInfo(b)), f && (m = this.endTimer(m), this.activeTimers.push({ name: t.constructor.name, query: this.getQueryTime(m) })); const g = A().get("WEBGL_FLUSH_THRESHOLD"); if (g > 0) { const b = Me(); b - this.lastGlFlushTime > g && (this.gpgpu.gl.flush(), this.lastGlFlushTime = b) } if (!A().getBool("WEBGL_LAZILY_UNPACK") && c.isPacked && r === !1) { const b = this.unpackTensor(a); return this.disposeIntermediateTensorInfo(a), b } return a } compileAndRun(t, e, s, o, r = !1) { return s = s || e[0].dtype, this.runWebGLProgram(t, e, s, o, r) } getAndSaveBinary(t, e) { return t in this.binaryCache || (this.binaryCache[t] = e()), this.binaryCache[t] } getTextureManager() { return this.textureManager } dispose() { this.disposed || (A().getBool("IS_TEST") || Object.keys(this.binaryCache).forEach(e => { this.gpgpu.deleteProgram(this.binaryCache[e].webGLProgram), delete this.binaryCache[e] }), this.textureManager.dispose(), this.canvas != null && typeof HTMLCanvasElement < "u" && this.canvas instanceof HTMLCanvasElement ? this.canvas.remove() : this.canvas = null, this.gpgpuCreatedLocally && (this.gpgpu.program = null, this.gpgpu.dispose()), this.disposed = !0) } floatPrecision() { return this.floatPrecisionValue == null && (this.floatPrecisionValue = M(() => { if (!A().get("WEBGL_RENDER_FLOAT32_ENABLED")) { const t = A().getBool("DEBUG"); A().set("DEBUG", !1); const e = this.abs(Gt(1e-8)).dataSync()[0]; if (A().set("DEBUG", t), e > 0) return 32 } return 16 })), this.floatPrecisionValue } epsilon() { return this.floatPrecision() === 32 ? wz : vz } uploadToGPU(t) { const e = this.texData.get(t), { shape: s, dtype: o, values: r, texture: i, usage: a, isPacked: c } = e; if (i != null) return; const l = this.activeTimers != null; let u; l && (u = Me()); let d = e.texShape; if (d == null && (d = QM(s, c), e.texShape = d), r != null) { const h = yl(s); let p, f = d[1], m = d[0]; const g = r instanceof Uint8Array || r instanceof Uint8ClampedArray; (c || !g) && ([f, m] = or(d[0], d[1])), c ? p = new QF(h, g) : p = new qy(h, g); const b = g ? [m, f] : d, x = this.makeTensorInfo(b, o), I = this.texData.get(x.dataId); g ? I.usage = an.PIXELS : I.usage = an.UPLOAD, I.texShape = b, this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(x.dataId), f, m, r); const y = [[m, f]], C = !0, w = this.runWebGLProgram(p, [x], o, y, C), k = this.texData.get(w.dataId); e.texShape = k.texShape, e.isPacked = k.isPacked, e.usage = k.usage, A().get("ENGINE_COMPILE_ONLY") ? this.disposeData(w.dataId) : (e.texture = k.texture, e.values = null, this.texData.delete(w.dataId)), this.disposeIntermediateTensorInfo(x), l && (this.uploadWaitMs += Me() - u) } else { const h = this.acquireTexture(d, a, o, c); e.texture = h } } convertAndCacheOnCPU(t, e) { const s = this.texData.get(t), { dtype: o } = s; return e != null && (s.values = Rz(e, o)), s.values } acquireTexture(t, e, s, o) { if (this.numBytesInGPU += this.computeBytes(t, s), !this.warnedAboutMemory && this.numBytesInGPU > this.numMBBeforeWarning * 1024 * 1024) { const r = (this.numBytesInGPU / 1024 / 1024).toFixed(2); this.warnedAboutMemory = !0, console.warn(`High memory usage in GPU: ${r} MB, most likely due to a memory leak`) } return this.textureManager.acquireTexture(t, e, o) } computeBytes(t, e) { return t[0] * t[1] * fa(e) } checkCompileCompletion() { for (const [, t] of Object.entries(this.binaryCache)) this.checkCompletion_(t) } async checkCompileCompletionAsync() { const t = []; if (this.gpgpu.parallelCompilationExtension) { for (const [, e] of Object.entries(this.binaryCache)) t.push(this.checkCompletionAsync_(e)); return Promise.all(t) } else { for (const [, e] of Object.entries(this.binaryCache)) { const s = new Promise(o => { try { this.checkCompletion_(e), o(!0) } catch (r) { throw r } }); t.push(s) } return Promise.all(t) } } async checkCompletionAsync_(t) { return this.gpgpu.gl.getProgramParameter(t.webGLProgram, this.gpgpu.parallelCompilationExtension.COMPLETION_STATUS_KHR) ? this.checkCompletion_(t) : (await Mc(), this.checkCompletionAsync_(t)) } checkCompletion_(t) { if (this.gpgpu.gl.getProgramParameter(t.webGLProgram, this.gpgpu.gl.LINK_STATUS) === !1) throw console.log(this.gpgpu.gl.getProgramInfoLog(t.webGLProgram)), this.gpgpu.gl.getShaderParameter(t.fragmentShader, this.gpgpu.gl.COMPILE_STATUS) === !1 ? (Ky(t.source, this.gpgpu.gl.getShaderInfoLog(t.fragmentShader)), new Error("Failed to compile fragment shader.")) : new Error("Failed to link vertex and fragment shaders."); return !0 } getUniformLocations() { for (const [, t] of Object.entries(this.binaryCache)) { const { uniformLocations: e, customUniformLocations: s, infLoc: o, nanLoc: r, inShapesLocations: i, inTexShapesLocations: a, outShapeLocation: c, outShapeStridesLocation: l, outTexShapeLocation: u } = Jy(this.gpgpu, t.program, t.webGLProgram); t.uniformLocations = e, t.customUniformLocations = s, t.infLoc = o, t.nanLoc = r, t.inShapesLocations = i, t.inTexShapesLocations = a, t.outShapeLocation = c, t.outShapeStridesLocation = l, t.outTexShapeLocation = u } } createTensorFromGPUData(t, e, s) { t.channels = t.channels || "RGBA"; const { texture: o, height: r, width: i, channels: a } = t, c = Ft().backend; if (!c.gpgpu.gl.isTexture(o)) throw new Error("The texture is invalid. Also, please make sure the texture and the TFJS WebGL backend are using the same canvas. If you want to use your own custom canvas, you have to create and use the custom TFJS WebGL backend created from the canvas through 'new tf.MathBackendWebGL(customCanvas)'."); const l = c.writeTexture(o, e, s, r, i, a); return Ft().makeTensorFromDataId(l, e, s, c) } } Sl.nextDataId = 0; function Rz(n, t) { if (t === "float32" || t === "complex64") return n; if (t === "int32" || t === "bool") { const e = t === "int32" ? new Int32Array(n.length) : new Uint8Array(n.length); for (let s = 0; s < e.length; ++s)e[s] = Math.round(n[s]); return e } else throw new Error(`Unknown dtype ${t}`) }/**
 * @license
 * Copyright 2020 Google Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */sm() && xm("webgl", () => new Sl, 2);/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kp = `
  if (isnan(a)) return a;
  if (isnan(b)) return b;
`; class dr {
        constructor(t, e, s) {
            this.variableNames = ["A", "B"], this.outputShape = gt(e, s), this.enableShapeUniforms = Ee(this.outputShape.length), this.userCode = `
      float binaryOperation(float a, float b) {
        ${t}
      }

      void main() {
        float a = getAAtOutCoords();
        float b = getBAtOutCoords();
        setOutput(binaryOperation(a, b));
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ea = `
  result.r = isNaN.r ? NAN : result.r;
  result.g = isNaN.g ? NAN : result.g;
  result.b = isNaN.b ? NAN : result.b;
  result.a = isNaN.a ? NAN : result.a;
`; class na {
        constructor(t, e, s, o = !1) {
            this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = gt(e, s); const r = this.outputShape.length; this.enableShapeUniforms = Ee(r); let i = ""; if (o) if (r === 0 || Z(this.outputShape) === 1) i = `
          result.y = 0.;
          result.z = 0.;
          result.w = 0.;
        `; else if (i = `
          ${Xt(r)} coords = getOutputCoords();
        `, r === 1) this.enableShapeUniforms ? i += `
            result.y = (coords + 1) >= outShape ? 0. : result.y;
            result.z = 0.;
            result.w = 0.;
          `: i += `
            result.y = (coords + 1) >= ${this.outputShape[0]} ? 0. : result.y;
            result.z = 0.;
            result.w = 0.;
          `; else {
                const c = De("coords", r); this.enableShapeUniforms ? i += `
            bool nextRowOutOfBounds =
              (${c[r - 2]} + 1) >= outShape[${r} - 2];
            bool nextColOutOfBounds =
              (${c[r - 1]} + 1) >= outShape[${r} - 1];
            result.y = nextColOutOfBounds ? 0. : result.y;
            result.z = nextRowOutOfBounds ? 0. : result.z;
            result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
          `: i += `
            bool nextRowOutOfBounds =
              (${c[r - 2]} + 1) >= ${this.outputShape[r - 2]};
            bool nextColOutOfBounds =
              (${c[r - 1]} + 1) >= ${this.outputShape[r - 1]};
            result.y = nextColOutOfBounds ? 0. : result.y;
            result.z = nextRowOutOfBounds ? 0. : result.z;
            result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
          `} this.userCode = `
      vec4 binaryOperation(vec4 a, vec4 b) {
        ${t}
      }

      void main() {
        vec4 a = getAAtOutCoords();
        vec4 b = getBAtOutCoords();

        vec4 result = binaryOperation(a, b);
        ${i}

        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ye(n) { const { inputs: t, backend: e } = n, { x: s } = t; return e.incRef(s.dataId), { dataId: s.dataId, shape: s.shape, dtype: s.dtype } } const $z = { kernelName: Xr, backendName: "webgl", kernelFunc: Ye };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ws(n) { const { inputs: t, backend: e } = n, { real: s, imag: o } = t, r = e.makeTensorInfo(s.shape, "complex64"), i = e.texData.get(r.dataId), a = Ye({ inputs: { x: s }, backend: e }), c = Ye({ inputs: { x: o }, backend: e }); return i.complexTensorInfos = { real: a, imag: c }, r } const Gz = { kernelName: ou, backendName: "webgl", kernelFunc: Ws };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const f1 = "return (a < 0.) ? b * a : a;", m1 = `
  vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
  return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
`; function Lz(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { alpha: r } = s, i = e.makeTensorInfo([], "float32", ps(r, "float32")), a = A().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new na(m1, o.shape, i.shape) : new dr(f1, o.shape, i.shape), c = e.runWebGLProgram(a, [o, i], "float32"); return e.disposeIntermediateTensorInfo(i), c } const Ez = { kernelName: Ma, backendName: "webgl", kernelFunc: Lz };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const g1 = "return (a < 0.) ? b * a : a;", b1 = `
  vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
  return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
`; function Dz(n) { const { inputs: t, backend: e } = n, { x: s, alpha: o } = t, r = A().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new na(b1, s.shape, o.shape) : new dr(g1, s.shape, o.shape); return e.runWebGLProgram(r, [s, o], "float32") } const Wz = { kernelName: tc, backendName: "webgl", kernelFunc: Dz };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const hr = "if (isnan(x)) return x;"; function Tt({ opSnippet: n, packedOpSnippet: t, cpuKernelImpl: e, dtype: s }) { return ({ inputs: o, backend: r }) => { const { x: i } = o, a = r, c = s || i.dtype; if (a.shouldExecuteOnCPU([i]) && e != null) { const d = a.texData.get(i.dataId), h = e(d.values, c); return a.makeTensorInfo(i.shape, c, h) } const l = A().getBool("WEBGL_PACK_UNARY_OPERATIONS") && t != null; let u; return l ? u = new Ds(i.shape, t) : u = new Yn(i.shape, n), a.runWebGLProgram(u, [i], c) } } function we({ opSnippet: n, packedOpSnippet: t, checkOutOfBounds: e = !1, supportsComplex: s = !1, cpuKernelImpl: o, dtype: r }) { return ({ inputs: i, backend: a }) => { const { a: c, b: l } = i, u = a; if (s && c.dtype === "complex64") { const f = u.texData.get(c.dataId), m = u.texData.get(l.dataId), [g, b] = [[f.complexTensorInfos.real, m.complexTensorInfos.real], [f.complexTensorInfos.imag, m.complexTensorInfos.imag]].map(I => { const [y, C] = I, w = { dataId: y.dataId, dtype: y.dtype, shape: c.shape }, k = { dataId: C.dataId, dtype: C.dtype, shape: l.shape }, S = new dr(n, c.shape, l.shape); return u.runWebGLProgram(S, [w, k], Ze(y.dtype, C.dtype)) }), x = Ws({ inputs: { real: g, imag: b }, backend: u }); return u.disposeIntermediateTensorInfo(g), u.disposeIntermediateTensorInfo(b), x } const d = r || Ze(c.dtype, l.dtype); if ((c.dtype === "string" || l.dtype === "string" || u.shouldExecuteOnCPU([c, l])) && o != null) { const f = u.texData.get(c.dataId).values, m = u.texData.get(l.dataId).values, g = c.dtype === "string" ? co(f) : f, b = c.dtype === "string" ? co(m) : m, [x, I] = o(c.shape, l.shape, g, b, d), y = u.makeTensorInfo(I, d), C = u.texData.get(y.dataId); return C.values = x, y } const h = A().getBool("WEBGL_PACK_BINARY_OPERATIONS") && t != null; let p; return h ? p = new na(t, c.shape, l.shape, e) : p = new dr(n, c.shape, l.shape), u.runWebGLProgram(p, [c, l], d) } } function sa(n, t = !1) { if (n === "linear") return t ? mz : uz; if (n === "relu") return t ? bz : hz; if (n === "elu") return t ? gz : dz; if (n === "relu6") return t ? xz : pz; if (n === "prelu") return t ? b1 : g1; if (n === "leakyrelu") return t ? m1 : f1; if (n === "sigmoid") return t ? yz : fz; throw new Error(`Activation ${n} has not been implemented for the WebGL backend.`) }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class x1 {
        constructor(t, e, s, o = !1, r = !1, i = !1, a = null, c = !1, l = !1) {
            this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = s, this.enableShapeUniforms = Ee(this.outputShape.length); const u = o ? t[1] : t[2], d = Math.ceil(u / 2), h = o ? "i * 2, rc.y" : "rc.y, i * 2", p = r ? "rc.z, i * 2" : "i * 2, rc.z", f = o ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"], m = r ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"]; let g = "", b = ""; a && (c ? g = `vec4 activation(vec4 a) {
          vec4 b = getPreluActivationWeightsAtOutCoords();
          ${a}
        }`: l ? g = `vec4 activation(vec4 a) {
          vec4 b = getLeakyreluAlphaAtOutCoords();
          ${a}
        }`: g = `vec4 activation(vec4 x) {
          ${a}
        }`, b = "result = activation(result);"); const x = i ? "result += getBiasAtOutCoords();" : ""; i && this.variableNames.push("bias"), c && this.variableNames.push("preluActivationWeights"), l && this.variableNames.push("leakyreluAlpha"); let I = "rc.x", y = "rc.x"; t[0] < e[0] ? I = `imod(rc.x, ${t[0]})` : e[0] < t[0] && (y = `imod(rc.x, ${e[0]})`), this.userCode = `
      ${g}
      // Don't use uniform for sharedDimensionPacked for performance.
      const float sharedDimension = ${d}.0;

      vec4 dot2x2ARowBCol(ivec3 rc) {
        vec4 result = vec4(0);
        int batchA = ${I};
        int batchB = ${y};
        for (int i = 0; i < ${d}; i++) {
          vec4 a = getMatrixA(batchA, ${h});
          vec4 b = getMatrixB(batchB, ${p});

          // These swizzled products need to be separately added.
          // See: https://github.com/tensorflow/tfjs/issues/1735
          result += (${f[0]} * ${m[0]});
          result += (${f[1]} * ${m[1]});
        }
        return result;
      }

      void main() {
        ivec3 rc = getOutputCoords();
        vec4 result = dot2x2ARowBCol(rc);

        ${x}

        ${b}

        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const y1 = { REAL: "return areal * breal - aimag * bimag;", IMAG: "return areal * bimag + aimag * breal;" }; class I1 {
        constructor(t, e, s) {
            this.variableNames = ["AReal", "AImag", "BReal", "BImag"], this.outputShape = gt(e, s), this.userCode = `
      float binaryOpComplex(
          float areal, float aimag, float breal, float bimag) {
        ${t}
      }

      void main() {
        float areal = getARealAtOutCoords();
        float aimag = getAImagAtOutCoords();
        float breal = getBRealAtOutCoords();
        float bimag = getBImagAtOutCoords();
        setOutput(binaryOpComplex(areal, aimag, breal, bimag));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const C1 = "return a * b;"; function Tp(n) { const { inputs: t, backend: e } = n, { a: s, b: o } = t, r = Ze(s.dtype, o.dtype); if (s.dtype === "complex64") { const a = e.texData.get(s.dataId), c = e.texData.get(o.dataId), l = new I1(y1.REAL, s.shape, o.shape), u = new I1(y1.IMAG, s.shape, o.shape), d = [{ dataId: a.complexTensorInfos.real.dataId, dtype: a.complexTensorInfos.real.dtype, shape: s.shape }, { dataId: a.complexTensorInfos.imag.dataId, dtype: a.complexTensorInfos.imag.dtype, shape: s.shape }, { dataId: c.complexTensorInfos.real.dataId, dtype: c.complexTensorInfos.real.dtype, shape: o.shape }, { dataId: c.complexTensorInfos.imag.dataId, dtype: c.complexTensorInfos.imag.dtype, shape: o.shape }], h = e.runWebGLProgram(l, d, "float32"), p = e.runWebGLProgram(u, d, "float32"), f = Ws({ inputs: { real: h, imag: p }, backend: e }); return e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p), f } if (e.shouldExecuteOnCPU([s, o])) { const a = e.texData.get(s.dataId), c = e.texData.get(o.dataId), [l, u] = WV(s.shape, o.shape, a.values, c.values, r), d = e.makeTensorInfo(u, r), h = e.texData.get(d.dataId); return h.values = l, d } let i; return A().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? i = new na(C1, s.shape, o.shape) : i = new dr(C1, s.shape, o.shape), e.runWebGLProgram(i, [s, o], r) } const Mz = { kernelName: Ur, backendName: "webgl", kernelFunc: Tp };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Fz(n, t, e) { const s = [rr(n.shape), ...ir(n.shape)], o = { dtype: n.dtype, shape: s, dataId: n.dataId }, r = [rr(t), ...ir(t)], i = new l1(r, s), a = !0, c = [s], l = e.runWebGLProgram(i, [o], n.dtype, c, a); return { dataId: l.dataId, shape: t, dtype: l.dtype } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function et(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { shape: r } = s, i = e, a = Z(o.shape), c = sf(r, a), l = Z(c); v(a === l, () => `The new shape (${c}) has ${l} elements and the old shape (${o.shape}) has ${a} elements. The new shape and old shape must have the same number of elements.`); const u = i.texData.get(o.dataId); return u.isPacked && !Cl(o.shape, c) && !(u.texture !== null && Cl(u.shape, c)) ? Fz(o, c, i) : (i.incRef(o.dataId), { dataId: o.dataId, shape: c, dtype: o.dtype }) } const Vz = { kernelName: nc, backendName: "webgl", kernelFunc: et };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class w1 {
        constructor(t, e) {
            this.variableNames = ["x"]; const { windowSize: s, batchSize: o, inSize: r, outSize: i } = t; this.outputShape = [o, i]; const a = Math.floor(s / 4) * 4, c = s % 4; let l = "sumValue += dot(values, ones);"; if (e != null) { const d = 1 / e; l = `sumValue += dot(values * ${Ro(d) ? d.toPrecision(2) : d}, ones);` } let u = ""; r % s > 0 && (u = `
        if (inIdx < 0 || inIdx >= ${r}) {
          return 0.0;
        }
      `), this.userCode = `
      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);

      float getValue(int batch, int inIdx) {
        ${u}
        return getX(batch, inIdx);
      }

      void main() {
        ivec2 coords = getOutputCoords();
        int batch = coords[0];
        int outIdx = coords[1];
        int inOffset = outIdx * ${s};

        float sumValue = 0.0;

        for (int i = 0; i < ${a}; i += 4) {
          int inIdx = inOffset + i;
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2),
            getValue(batch, inIdx + 3)
          );

          ${l}
        }

        int inIdx = inOffset + ${a};
        if (${c === 1}) {
          vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);

          ${l}
        } else if (${c === 2}) {
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1), 0.0, 0.0);

          ${l}
        } else if (${c === 3}) {
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2), 0.0);

          ${l}
        }
        setOutput(sumValue);
      }
    `}
    }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class zz {
        constructor(t, e) {
            this.variableNames = ["x"]; const { windowSize: s, batchSize: o, inSize: r, outSize: i } = t; this.outputShape = [o, i]; let a = "0.0", c = ""; e === "prod" ? a = "1.0" : e === "min" ? (a = "1.0 / 1e-20", c = "min") : e === "max" && (a = "-1.0 / 1e-20", c = "max"); let l = `${e}(${e}(${e}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`; e === "sum" ? l = "sumValue" : e === "prod" ? l = "prodValue" : e === "all" ? l = "allValue" : e === "any" && (l = "anyValue"); const u = Math.floor(s / 4) * 4, d = s % 4; let h = `
      if (${e === "sum"}) {
        sumValue += dot(values, ones);
      } else if (${e === "prod"}) {
        vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
        prodValue *= tmp[0] * tmp[1];
      } else {
        minMaxValue = ${c}(values, minMaxValue);
        if (${e === "min"} || ${e === "max"}) {
          minMaxValue = ${c}(values, minMaxValue);
          bvec4 isNaN = isnan(values);
          if (isNaN.r || isNaN.g || isNaN.b || isNaN.a) {
            minMaxValue = vec4(NAN);
          }
        }
      }
    `, p = "vec4"; e === "all" ? (a = "1.0", h = `
        bool reducedAllValue = all(values);
        float floatedReducedAllValue = float(reducedAllValue);
        allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
      `, p = "bvec4") : e === "any" && (a = "0.0", h = `
        bool reducedAnyValue = any(values);
        float floatedReducedAnyValue = float(reducedAnyValue);
        anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
      `, p = "bvec4"); let f = ""; r % s > 0 && (f = `
        if (inIdx < 0 || inIdx >= ${r}) {
          return initializationValue;
        }
      `), this.userCode = `
      const float initializationValue = ${a};
      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);

      float getValue(int batch, int inIdx) {
        ${f}
        return getX(batch, inIdx);
      }

      void main() {
        ivec2 coords = getOutputCoords();
        int batch = coords[0];
        int outIdx = coords[1];
        int inOffset = outIdx * ${s};

        vec4 minMaxValue = vec4(${a});
        float prodValue = 1.0;
        float sumValue = 0.0;
        float allValue = 1.0;
        float anyValue = 0.0;

        for (int i = 0; i < ${u}; i += 4) {
          int inIdx = inOffset + i;
          ${p} values = ${p}(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2),
            getValue(batch, inIdx + 3)
          );

          ${h}
        }

        int inIdx = inOffset + ${u};
        if (${d === 1}) {
          ${p} values = ${p}(
            getValue(batch, inIdx),
            initializationValue,
            initializationValue,
            initializationValue
          );

          ${h}
        } else if (${d === 2}) {
          ${p} values = ${p}(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            initializationValue,
            initializationValue
          );

          ${h}
        } else if (${d === 3}) {
          ${p} values = ${p}(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2),
            initializationValue
          );

          ${h}
        }
        setOutput(${l});
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Xz(n) { const t = []; for (; t.length === 0 || t[t.length - 1].outSize !== 1;) { const e = t.length ? t[t.length - 1].outSize : n[1], s = Fc(e); t.push({ inSize: e, windowSize: s, outSize: Math.ceil(e / s) }) } return t } function wo(n, t, e, s) { const o = Xz(n.shape); let r = n; for (let i = 0; i < o.length; i++) { const { inSize: a, windowSize: c, outSize: l } = o[i]; let u, d; e === "mean" ? u = i === 0 ? new w1({ windowSize: c, inSize: a, batchSize: n.shape[0], outSize: l }, a) : new w1({ windowSize: c, inSize: a, batchSize: n.shape[0], outSize: l }) : u = new zz({ windowSize: c, inSize: a, batchSize: n.shape[0], outSize: l }, e), d = r, r = s.runWebGLProgram(u, [r], t), d.dataId !== n.dataId && s.disposeIntermediateTensorInfo(d) } return r }/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Az {
        constructor(t, e) {
            this.variableNames = ["A"]; const s = new Array(t.length); for (let i = 0; i < s.length; i++)s[i] = t[e[i]]; this.outputShape = s, this.rank = s.length; const o = Xt(this.rank), r = Oz(e); this.userCode = `
    void main() {
      ${o} resRC = getOutputCoords();
      setOutput(getA(${r}));
    }
    `}
    } function Oz(n) { const t = n.length; if (t > 6) throw Error(`Transpose for rank ${t} is not yet supported`); const e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], s = new Array(t); for (let o = 0; o < n.length; o++)s[n[o]] = e[o]; return s.join() }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class Pz {
        constructor(t, e) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0; const s = new Array(t.length); for (let u = 0; u < s.length; u++)s[u] = t[e[u]]; if (this.outputShape = s, this.rank = s.length, this.rank > 6) throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`); const o = Xt(this.rank), r = c1("rc", this.rank), i = new Array(this.rank); for (let u = 0; u < e.length; u++)i[e[u]] = r[u]; const a = `vec2(${i.slice(-2).join()})`, c = `++${r[this.rank - 1]} < ${s[this.rank - 1]}`, l = `getChannel(getA(${i.join()}), ${a})`; this.userCode = `
    void main() {
      ${o} rc = getOutputCoords();
      vec4 result = vec4(0.);
      result[0] = ${l};
      if(${c}) {
        result[1] = ${l};
      }
      --${r[this.rank - 1]};
      if(++${r[this.rank - 2]} < ${s[this.rank - 2]}) {
        result[2] = ${l};
        if(${c}) {
          result[3] = ${l};
        }
      }
      setOutput(result);
    }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kl(n, t, e) { const s = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Pz(n.shape, t) : new Az(n.shape, t); return e.runWebGLProgram(s, [n], n.dtype) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Kz(n, t, e, s) { const o = t, r = n.shape.length, i = It(o, n.shape); let a = i; const c = Yt(a, r), l = c != null; let u = n; l && (u = kl(n, c, s), a = te(a.length, r)), Ie("sum", a, r); const [d, h] = fe(u.shape, a); let p = d; e && (p = oe(d, i)); const f = Z(h), g = Z(n.shape) / f, b = et({ inputs: { x: u }, attrs: { shape: [g, f] }, backend: s }), x = Yu(n.dtype), I = wo(b, x, "sum", s), y = et({ inputs: { x: I }, attrs: { shape: p }, backend: s }); return s.disposeIntermediateTensorInfo(b), s.disposeIntermediateTensorInfo(I), l && s.disposeIntermediateTensorInfo(u), y }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Tl(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s; return Kz(o, r, i, e) } const Zz = { kernelName: cc, backendName: "webgl", kernelFunc: Tl };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function We(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { perm: r } = s, i = e, a = o.shape.length, c = new Array(a); for (let u = 0; u < c.length; u++)c[u] = o.shape[r[u]]; let l; if (i.shouldExecuteOnCPU([o])) { const d = i.texData.get(o.dataId).values, h = Sp(d, o.shape, o.dtype, r, c); l = i.makeTensorInfo(c, o.dtype); const p = i.texData.get(l.dataId); p.values = h } else l = kl(o, r, i); return l } const Bz = { kernelName: Eo, backendName: "webgl", kernelFunc: We };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const v1 = 1e3; function Nl({ a: n, b: t, transposeA: e, transposeB: s, backend: o, bias: r = null, preluActivationWeights: i = null, leakyreluAlpha: a = 0, activation: c = null }) { const l = n.shape.length, u = t.shape.length, d = e ? n.shape[l - 2] : n.shape[l - 1], h = s ? t.shape[u - 1] : t.shape[u - 2], p = e ? n.shape[l - 1] : n.shape[l - 2], f = s ? t.shape[u - 2] : t.shape[u - 1], m = n.shape.slice(0, -2), g = t.shape.slice(0, -2), b = Z(m), x = Z(g), y = gt(n.shape.slice(0, -2), t.shape.slice(0, -2)).concat([p, f]); v(d === h, () => `Error in matMul: inner shapes (${d}) and (${h}) of Tensors with shapes ${n.shape} and ${t.shape} and transposeA=${e} and transposeB=${s} must match.`); const C = e ? [b, d, p] : [b, p, d], w = s ? [x, f, h] : [x, h, f], k = et({ inputs: { x: n }, backend: o, attrs: { shape: C } }), S = et({ inputs: { x: t }, backend: o, attrs: { shape: w } }), T = [k, S], R = Math.max(b, x), G = e ? k.shape[1] : k.shape[2], F = r != null, V = i != null, z = c === "leakyrelu", X = c != null ? sa(c, !0) : null, O = F || V || z || X != null; let B; if ((p === 1 || f === 1) && G > v1 && O === !1) { let H = k, U = S; e && (H = We({ inputs: { x: k }, backend: o, attrs: { perm: [0, 2, 1] } }), T.push(H)), s && (U = We({ inputs: { x: S }, backend: o, attrs: { perm: [0, 2, 1] } }), T.push(U)); const Y = f !== 1, j = f === 1; let J = H; Y && (J = et({ inputs: { x: H }, backend: o, attrs: { shape: [R, G, 1] } }), T.push(J)); const nt = f === 1 ? 2 : 1; let q = U; j && (q = et({ inputs: { x: U }, backend: o, attrs: { shape: [R, 1, G] } }), T.push(q)); const rt = Tp({ inputs: { a: J, b: q }, backend: o }); B = Tl({ inputs: { x: rt }, backend: o, attrs: { axis: nt, keepDims: !0 } }), T.push(rt) } else { const H = Ze(n.dtype, t.dtype), U = new x1(C, w, [R, p, f], e, s, F, X, V, z), Y = [k, S]; if (r != null && Y.push(r), V && Y.push(i), z) { const j = o.makeTensorInfo([], "float32", ps(a, "float32")); Y.push(j), T.push(j) } B = o.runWebGLProgram(U, Y, H) } const K = et({ inputs: { x: B }, backend: o, attrs: { shape: y } }); T.push(B); for (const H of T) o.disposeIntermediateTensorInfo(H); return K }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Hz(n) { const { inputs: t, backend: e, attrs: s } = n, { a: o, b: r, bias: i, preluActivationWeights: a } = t, { transposeA: c, transposeB: l, activation: u, leakyreluAlpha: d } = s; return Nl({ a: o, b: r, transposeA: c, transposeB: l, backend: e, bias: i, preluActivationWeights: a, leakyreluAlpha: d, activation: u }) } const _z = { kernelName: mc, backendName: "webgl", kernelFunc: Hz };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const S1 = "return abs(x);"; function Uz(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (e.shouldExecuteOnCPU([s]) && s.dtype !== "complex64") { const r = e.texData.get(s.dataId), i = i1(r.values); return e.makeTensorInfo(s.shape, s.dtype, i) } let o; return A().getBool("WEBGL_PACK_UNARY_OPERATIONS") ? o = new Ds(s.shape, S1) : o = new Yn(s.shape, S1), e.runWebGLProgram(o, [s], s.dtype) } const Yz = { kernelName: ma, backendName: "webgl", kernelFunc: Uz };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Qz = Cn + `
  if (abs(x) > 1.) {
    return NAN;
  }
  return acos(x);
`, Jz = Tt({ opSnippet: Qz }), jz = { kernelName: yr, backendName: "webgl", kernelFunc: Jz };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qz = Cn + `
  if (x < 1.0) return NAN;
return log(x + sqrt(x * x - 1.0));`, tX = Tt({ opSnippet: qz }), eX = { kernelName: Ir, backendName: "webgl", kernelFunc: tX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const k1 = "return a + b;", nX = we({ opSnippet: k1, packedOpSnippet: k1, supportsComplex: !0, cpuKernelImpl: fV }), sX = { kernelName: Lo, backendName: "webgl", kernelFunc: nX };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class oX {
        constructor(t, e) {
            this.outputShape = [], this.outputShape = t, this.variableNames = e.map((r, i) => `T${i}`); const s = []; this.variableNames.forEach(r => { s.push(`float v${r} = get${r}AtOutCoords();`) }); const o = this.variableNames.map(r => `v${r}`).join(" + "); this.userCode = `
      void main() {
        ${s.join(`
        `)}

        float result = ${o};
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class rX {
        constructor(t, e) {
            this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.variableNames = e.map((r, i) => `T${i}`); const s = []; this.variableNames.forEach(r => { s.push(`vec4 v${r} = get${r}AtOutCoords();`) }); const o = this.variableNames.map(r => `v${r}`).join(" + "); this.userCode = `
      void main() {
        ${s.join(`
        `)}

        vec4 result = ${o};
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Rl(n) { const { inputs: t, backend: e } = n, s = t; if (s.length === 1) return Ye({ inputs: { x: s[0] }, backend: e }); if (s.length > A().get("WEBGL_MAX_TEXTURES_IN_SHADER")) { const c = Math.floor(s.length / 2), l = Rl({ inputs: s.slice(0, c), backend: e }), u = Rl({ inputs: s.slice(c), backend: e }); return Rl({ inputs: [l, u], backend: e }) } const o = s.map(c => c.dtype).reduce((c, l) => Ze(c, l)), r = s.map(c => c.shape), a = A().getBool("WEBGL_PACK") ? new rX(s[0].shape, r) : new oX(s[0].shape, r); return e.runWebGLProgram(a, s, o) } const iX = { kernelName: jl, backendName: "webgl", kernelFunc: Rl };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s, a = o.shape.length, c = It(r, o.shape); let l = c; const u = Yt(l, a); let d = o; u != null && (d = We({ inputs: { x: o }, backend: e, attrs: { perm: u } }), l = te(l.length, a)), Ie("all", l, a); const [h, p] = fe(d.shape, l), f = Z(p), m = et({ inputs: { x: d }, backend: e, attrs: { shape: [-1, f] } }), g = wo(m, m.dtype, "all", e); let b; if (i) { const x = oe(h, c); b = et({ inputs: { x: g }, backend: e, attrs: { shape: x } }) } else b = et({ inputs: { x: g }, backend: e, attrs: { shape: h } }); return e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(g), u != null && e.disposeIntermediateTensorInfo(d), b } const cX = { kernelName: ql, backendName: "webgl", kernelFunc: aX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s, a = o.shape.length, c = It(r, o.shape); let l = c; const u = Yt(l, a); let d = o; u != null && (d = We({ inputs: { x: o }, backend: e, attrs: { perm: u } }), l = te(l.length, a)), Ie("any", l, a); const [h, p] = fe(d.shape, l), f = Z(p), m = et({ inputs: { x: d }, backend: e, attrs: { shape: [-1, f] } }), g = wo(m, m.dtype, "any", e); let b; if (i) { const x = oe(h, c); b = et({ inputs: { x: g }, backend: e, attrs: { shape: x } }) } else b = et({ inputs: { x: g }, backend: e, attrs: { shape: h } }); return e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(g), u != null && e.disposeIntermediateTensorInfo(d), b } const uX = { kernelName: tu, backendName: "webgl", kernelFunc: lX };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class dX {
        constructor(t, e, s) {
            this.variableNames = ["A"]; const { windowSize: o, batchSize: r, outSize: i } = t; s || this.variableNames.push("bestIndicesA"), this.outputShape = [r, i]; const a = e === "max" ? ">" : "<", c = s ? "inOffset + i;" : "round(getBestIndicesA(batch, inOffset + i));"; this.userCode = `
      void main() {
        ivec2 coords = getOutputCoords();
        int batch = coords[0];
        int outIdx = coords[1];
        int inOffset = outIdx * ${o};

        int bestIndex = inOffset;
        float bestValue = getA(batch, bestIndex);

        for (int i = 0; i < ${o}; i++) {
          int inIdx = ${c};
          float candidate = getA(batch, inIdx);
          if (candidate ${a} bestValue) {
            bestValue = candidate;
            bestIndex = inIdx;
          }
        }
        setOutput(float(bestIndex));
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class hX {
        constructor(t, e, s, o) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, v(t.length > 2, () => `Packed arg${s.charAt(0).toUpperCase() + s.slice(1)} supports only inputs with rank above 2.`); const r = t[t.length - 1], i = Math.ceil(r / e); this.outputShape = t.slice(0, -1), i > 1 && this.outputShape.push(i), o || this.variableNames.push("bestIndicesA"); const a = this.outputShape, c = a.length, l = Xt(c), u = De("coords", c); let d, h; if (i === 1) {
                h = c + 1; const S = Xt(h); d = `
        ${S} sourceLocR = ${S}(${u.join()}, 0);
        ++${u[c - 1]};
        ${S} sourceLocG = ${S}(${u.join()}, 0);
        ++${u[c - 2]};
        ${S} sourceLocA = ${S}(${u.join()}, 0);
        --${u[c - 1]};
        ${S} sourceLocB = ${S}(${u.join()}, 0);
        --${u[c - 2]};`
            } else h = c, d = `
        ${l} sourceLocR = coords;
        ++${u[c - 1]};
        ${l} sourceLocG = coords;
        ++${u[c - 2]};
        ${l} sourceLocA = coords;
        --${u[c - 1]};
        ${l} sourceLocB = coords;
        --${u[c - 2]};`; const p = ["x", "y", "z", "w", "u", "v"].slice(0, h), f = "." + p[h - 1], m = p.map(S => "int " + S), g = De("sourceLocR", h - 1).concat("inIdx.r"), b = De("sourceLocG", h - 1).concat("inIdx.g"), x = De("sourceLocB", h - 1).concat("inIdx.b"), I = De("sourceLocA", h - 1).concat("inIdx.a"), y = s === "max" ? "greaterThan" : "lessThan", C = o ? "" : `
          inIdx = round(vec4(getBestIndicesAChannel(${g.join()}),
                             getBestIndicesAChannel(${b.join()}),
                             getBestIndicesAChannel(${x.join()}),
                             getBestIndicesAChannel(${I.join()})));`, w = `vec4(
            getAChannel(${g.join()}),
            hasNextCol ? getAChannel(${b.join()}) : 0.,
            hasNextRow ? getAChannel(${x.join()}) : 0.,
            hasNextRow && hasNextCol ? getAChannel(${I.join()}) : 0.)`, k = o ? "" : `
      float getBestIndicesAChannel(${m.join()}) {
        return getChannel(getBestIndicesA(${p.join()}),
                                          vec2(${p.slice(-2).join()}));
      }`; this.userCode = `
      float getAChannel(${m.join()}) {
        return getChannel(getA(${p.join()}),
                               vec2(${p.slice(-2).join()}));
      }
      ${k}
      void main() {
        ${l} coords = getOutputCoords();
        bool hasNextCol = ${u[c - 1]} < ${a[c - 1] - 1};
        bool hasNextRow = ${u[c - 2]} < ${a[c - 2] - 1};
        ${d}
        ivec4 srcIdx = ivec4(sourceLocR${f}, sourceLocG${f},
          sourceLocB${f}, sourceLocA${f}) * ${e};
        ivec4 inIdx = srcIdx;
        vec4 bestIndex = vec4(inIdx);
        vec4 bestValue = ${w};

        for (int i = 0; i < ${e}; i++) {
          inIdx = srcIdx;
          ${C}
          vec4 candidate = ${w};
          bvec4 nan = isnan(candidate);
          bvec4 replace = bvec4(
            vec4(${y}(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));

          bestValue = vec4(replace.x  ? candidate.x : bestValue.x,
                           replace.y  ? candidate.y : bestValue.y,
                           replace.z  ? candidate.z : bestValue.z,
                           replace.w  ? candidate.w : bestValue.w);
          bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));
          srcIdx++;
        }
        setOutput(bestIndex);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function T1(n, t, e, s = null) { let o = t.shape[0], r = t.shape[1]; s != null && (o = s.shape[0], r = s.shape[1]); const i = Fc(r), a = { windowSize: i, inSize: r, batchSize: o, outSize: Math.ceil(r / i) }, c = new dX(a, e, s == null), l = [t]; s != null && l.push(s); const u = n.runWebGLProgram(c, l, "int32"); if (u.shape[1] === 1) return u; const d = T1(n, t, e, u); return n.disposeIntermediateTensorInfo(u), d } function N1(n, t, e, s = null) { const o = s != null ? s.shape : t.shape, r = o[o.length - 1], i = Fc(r), a = new hX(o, i, e, s == null), c = s == null ? [t] : [t, s], l = n.runWebGLProgram(a, c, "int32"); if (l.shape.length === t.shape.length) { const u = N1(n, t, e, l); return n.disposeIntermediateTensorInfo(l), u } return l } function R1(n, t, e, s) { const o = [e]; if (Ie("arg" + s.charAt(0).toUpperCase() + s.slice(1), o, t.shape.length), !A().getBool("WEBGL_PACK_REDUCE") || t.shape.length <= 2) { const r = [], i = n.texData.get(t.dataId), a = i !== null && i.isPacked; let c = t; a && (c = n.unpackTensor(t), r.push(c)); const [l, u] = fe(c.shape, o), d = Z(u), h = et({ inputs: { x: c }, backend: n, attrs: { shape: [-1, d] } }); r.push(h); const p = T1(n, h, s); r.push(p); const f = et({ inputs: { x: p }, backend: n, attrs: { shape: l } }); return r.forEach(m => n.disposeIntermediateTensorInfo(m)), f } return N1(n, t, s) }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r } = s; let i = It(r, o.shape); const a = Yt(i, o.shape.length); let c = o; const l = []; a != null && (c = We({ inputs: { x: o }, backend: e, attrs: { perm: a } }), l.push(c), i = te(i.length, c.shape.length)), Ie("argMax", [i[0]], c.shape.length); const u = R1(e, c, i[0], "max"); return l.forEach(d => e.disposeIntermediateTensorInfo(d)), u } const fX = { kernelName: ga, backendName: "webgl", kernelFunc: pX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r } = s; let i = It(r, o.shape); const a = Yt(i, o.shape.length); let c = o; const l = []; a != null && (c = We({ inputs: { x: o }, backend: e, attrs: { perm: a } }), l.push(c), i = te(i.length, c.shape.length)), Ie("argMin", [i[0]], c.shape.length); const u = R1(e, c, i[0], "min"); return l.forEach(d => e.disposeIntermediateTensorInfo(d)), u } const gX = { kernelName: ba, backendName: "webgl", kernelFunc: mX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const bX = Cn + `
  if (abs(x) > 1.) {
    return NAN;
  }
  return asin(x);
`, xX = Tt({ opSnippet: bX }), yX = { kernelName: Cr, backendName: "webgl", kernelFunc: xX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const IX = Cn + "return log(x + sqrt(x * x + 1.0));", CX = Tt({ opSnippet: IX }), wX = { kernelName: wr, backendName: "webgl", kernelFunc: CX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const vX = Cn + `
  return atan(x);
`, SX = Tt({ opSnippet: vX }), kX = { kernelName: vr, backendName: "webgl", kernelFunc: SX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const TX = kp + `
  return atan(a, b);
`, NX = `
  vec4 result = atan(a, b);
  bvec4 isNaNA = isnan(a);
  bvec4 isNaNB = isnan(b);
  bvec4 isNaN = bvec4(isNaNA.x || isNaNB.x, isNaNA.y || isNaNB.y, isNaNA.z || isNaNB.z, isNaNA.w || isNaNB.w);
  `+ ea + `
  return result;
`, RX = we({ opSnippet: TX, packedOpSnippet: NX }), $X = { kernelName: kr, backendName: "webgl", kernelFunc: RX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const GX = Cn + `
  if ((x < -1.0) || (x > 1.0)) return NAN;
return (log(1.0 + x) - log(1.0 - x)) / 2.0;`, LX = Tt({ opSnippet: GX }), EX = { kernelName: Sr, backendName: "webgl", kernelFunc: LX };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class oa {
        constructor(t, e, s, o = !1, r = !1) {
            if (this.variableNames = ["x"], e === "avg" && s) throw new Error("Cannot compute positions for average pool."); const i = t.filterWidth, a = t.strideHeight, c = t.strideWidth, l = t.dilationHeight, u = t.dilationWidth, d = t.effectiveFilterHeight, h = t.effectiveFilterWidth, p = t.padInfo.top, f = t.padInfo.left; this.outputShape = t.outShape; const m = e === "avg", g = `((batch  * ${t.inHeight} + xR) * ${t.inWidth} + xC) * ${t.inChannels} + d`, b = `(xR * ${t.inWidth} + xC) * ${t.inChannels} + d`; let x = "0.0"; if (m || (x = "-1.0 / 1e-20"), s) {
                const S = ">="; this.userCode = `
        const ivec2 strides = ivec2(${a}, ${c});
        const ivec2 pads = ivec2(${p}, ${f});

        void main() {
          ivec4 coords = getOutputCoords();
          int batch = coords[0];
          int d = coords[3];

          ivec2 xRCCorner = coords.yz * strides - pads;
          int xRCorner = xRCCorner.x;
          int xCCorner = xRCCorner.y;

          // max/min x(?, ?, d) to get y(yR, yC, d).
          // ? = to be determined
          float minMaxValue = 0.0;
          float minMaxValueFound = 0.0;
          int minMaxPosition = 0;
          float avgValue = 0.0;

          for (int wR = 0; wR < ${d};
              wR += ${l}) {
            int xR = xRCorner + wR;

            if (xR < 0 || xR >= ${t.inHeight}) {
              continue;
            }

            for (int wC = 0; wC < ${h};
                wC += ${u}) {
              int xC = xCCorner + wC;

              if (xC < 0 || xC >= ${t.inWidth}) {
                continue;
              }

              float value = getX(batch, xR, xC, d);

              // If a min / max value has already been found, use it. If not,
              // use the current value.
              float currMinMaxValue = mix(
                  value, minMaxValue, minMaxValueFound);
              if (value ${S} currMinMaxValue) {
                minMaxValue = value;
                minMaxValueFound = 1.0;
                minMaxPosition = ${o ? r ? g : b : `wR * ${h} + wC`};
              }
            }
          }
          setOutput(float(minMaxPosition));
        }
      `; return
            } const I = "max"; let y = `${e}(${e}(${e}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`; e === "avg" && (y = "avgValue / max(count, 1.0)"); const C = Math.floor(i / 4) * 4, w = i % 4, k = `
      if (${m}) {
        avgValue += dot(values, ones);
      } else {
        minMaxValue = ${I}(values, minMaxValue);
      }
    `; this.userCode = `
      const ivec2 strides = ivec2(${a}, ${c});
      const ivec2 pads = ivec2(${p}, ${f});
      const float initializationValue = ${x};
      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);

      float count = 0.0;

      float getValue(int batch, int xR, int xC, int d) {
        if (xC < 0 || xC >= ${t.inWidth}) {
          return initializationValue;
        }
        count += 1.0;
        return getX(batch, xR, xC, d);
      }

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords[0];
        int d = coords[3];

        ivec2 xRCCorner = coords.yz * strides - pads;
        int xRCorner = xRCCorner.x;
        int xCCorner = xRCCorner.y;

        // max/min x(?, ?, d) to get y(yR, yC, d).
        // ? = to be determined
        vec4 minMaxValue = vec4(${x});
        float avgValue = 0.0;
        count = 0.0;

        for (int wR = 0; wR < ${d};
            wR += ${l}) {
          int xR = xRCorner + wR;

          if (xR < 0 || xR >= ${t.inHeight}) {
            continue;
          }

          for (int wC = 0; wC < ${C}; wC += 4) {
            int xC = xCCorner + wC * ${u};

            vec4 values = vec4(
              getValue(batch, xR, xC, d),
              getValue(batch, xR, xC + ${u}, d),
              getValue(batch, xR, xC + 2 * ${u}, d),
              getValue(batch, xR, xC + 3 * ${u}, d)
            );

            ${k}
          }

          int xC = xCCorner + ${C};
          if (${w === 1}) {
            vec4 values = vec4(
              getValue(batch, xR, xC, d),
              initializationValue,
              initializationValue,
              initializationValue
            );

            ${k}
          } else if (${w === 2}) {
            vec4 values = vec4(
              getValue(batch, xR, xC, d),
              getValue(batch, xR, xC + ${u}, d),
              initializationValue,
              initializationValue
            );

            ${k}
          } else if (${w === 3}) {
            vec4 values = vec4(
              getValue(batch, xR, xC, d),
              getValue(batch, xR, xC + ${u}, d),
              getValue(batch, xR, xC + 2 * ${u}, d),
              initializationValue
            );

            ${k}
          }
        }
        setOutput(${y});
      }
    `}
    } class Np {
        constructor(t, e, s, o = !1, r = !1) {
            if (this.variableNames = ["x"], e === "avg" && s) throw new Error("Cannot compute positions for average pool."); const i = t.filterWidth, a = t.strideDepth, c = t.strideHeight, l = t.strideWidth, u = t.dilationDepth, d = t.dilationHeight, h = t.dilationWidth, p = t.effectiveFilterDepth, f = t.effectiveFilterHeight, m = t.effectiveFilterWidth, g = t.padInfo.front, b = t.padInfo.top, x = t.padInfo.left; this.outputShape = t.outShape; const I = e === "avg"; let y = "0.0"; if (I || (y = "-1.0 / 1e-20"), s) {
                const R = ">="; this.userCode = `
        const ivec3 strides =
            ivec3(${a}, ${c}, ${l});
        const ivec3 pads = ivec3(${g}, ${b}, ${x});

        void main() {
          ivec5 coords = getOutputCoords();
          int batch = coords.x;
          int ch = coords.u;

          ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
          int xDCorner = xCorner.x;
          int xRCorner = xCorner.y;
          int xCCorner = xCorner.z;

          // max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
          // ? = to be determined
          float minMaxValue = 0.0;
          float minMaxValueFound = 0.0;
          int minMaxPosition = 0;

          for (int wD = 0; wD < ${p};
              wD += ${u}) {
            int xD = xDCorner + wD;

            if (xD < 0 || xD >= ${t.inDepth}) {
              continue;
            }

            for (int wR = 0; wR < ${f};
                wR += ${d}) {
              int xR = xRCorner + wR;

              if (xR < 0 || xR >= ${t.inHeight}) {
                continue;
              }

              for (int wC = 0; wC < ${m};
                  wC += ${h}) {
                int xC = xCCorner + wC;

                if (xC < 0 || xC >= ${t.inWidth}) {
                  continue;
                }

                float value = getX(batch, xD, xR, xC, ch);

                // If a min / max value has already been found, use it. If not,
                // use the current value.
                float currMinMaxValue = mix(
                    value, minMaxValue, minMaxValueFound);
                if (value ${R} currMinMaxValue) {
                  minMaxValue = value;
                  minMaxValueFound = 1.0;
                  minMaxPosition = ${o ? r ? `(((batch * ${t.inDepth} + xD) * ${t.inHeight} + xR) * ${t.inWidth} + xC) * ${t.inChannels} + ch` : `((xD * ${t.inHeight} + xR) * ${t.inWidth} + xC) * ${t.inChannels} + ch` : `wD * ${f} * ${m} +
                      wR * ${m} + wC`};
                }
              }
            }
          }
          setOutput(float(minMaxPosition));
        }
      `; return
            } const C = "max"; let w = `${e}(${e}(${e}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`; e === "avg" && (w = "avgValue / max(count, 1.0)"); const k = Math.floor(i / 4) * 4, S = i % 4, T = `
      if (${I}) {
        avgValue += dot(values, ones);
      } else {
        minMaxValue = ${C}(values, minMaxValue);
      }
    `; this.userCode = `
      const ivec3 strides =
        ivec3(${a}, ${c}, ${l});
      const ivec3 pads = ivec3(${g}, ${b}, ${x});
      const float initializationValue = ${y};
      const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);

      float count = 0.0;

      float getValue(int batch, int xD, int xR, int xC, int ch) {
        if (xC < 0 || xC >= ${t.inWidth}) {
          return initializationValue;
        }
        count += 1.0;
        return getX(batch, xD, xR, xC, ch);
      }

      void main() {
        ivec5 coords = getOutputCoords();
        int batch = coords.x;
        int ch = coords.u;

        ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
        int xDCorner = xCorner.x;
        int xRCorner = xCorner.y;
        int xCCorner = xCorner.z;

        // max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
        // ? = to be determined
        vec4 minMaxValue = vec4(${y});
        float avgValue = 0.0;
        count = 0.0;

        for (int wD = 0; wD < ${p};
            wD += ${u}) {
          int xD = xDCorner + wD;

          if (xD < 0 || xD >= ${t.inDepth}) {
            continue;
          }

          for (int wR = 0; wR < ${f};
            wR += ${d}) {
            int xR = xRCorner + wR;

            if (xR < 0 || xR >= ${t.inHeight}) {
              continue;
            }

            for (int wC = 0; wC < ${k}; wC += 4) {
              int xC = xCCorner + wC * ${h};

              vec4 values = vec4(
                getValue(batch, xD, xR, xC, ch),
                getValue(batch, xD, xR, xC + ${h}, ch),
                getValue(batch, xD, xR, xC + 2 * ${h}, ch),
                getValue(batch, xD, xR, xC + 3 * ${h}, ch)
              );

              ${T}
            }

            int xC = xCCorner + ${k};
            if (${S === 1}) {
              vec4 values = vec4(
                getValue(batch, xD, xR, xC, ch),
                initializationValue,
                initializationValue,
                initializationValue
              );

              ${T}
            } else if (${S === 2}) {
              vec4 values = vec4(
                getValue(batch, xD, xR, xC, ch),
                getValue(batch, xD, xR, xC + ${h}, ch),
                initializationValue,
                initializationValue
              );

              ${T}
            } else if (${S === 3}) {
              vec4 values = vec4(
                getValue(batch, xD, xR, xC, ch),
                getValue(batch, xD, xR, xC + ${h}, ch),
                getValue(batch, xD, xR, xC + 2 * ${h}, ch),
                initializationValue
              );

              ${T}
            }
          }
        }
        setOutput(${w});
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function DX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t; qi(o, "avgPool"); const { filterSize: r, strides: i, pad: a, dimRoundingMode: c } = s, l = 1; v(Te(i, l), () => `Error in avgPool: Either strides or dilations must be 1. Got strides ${i} and dilations '${l}'`); const u = hn(o.shape, r, i, l, a, c); if (u.filterWidth === 1 && u.filterHeight === 1 && Rt(u.inShape, u.outShape)) return Ye({ inputs: { x: o }, backend: e }); const d = new oa(u, "avg", !1); return e.runWebGLProgram(d, [o], "float32") } const WX = { kernelName: xa, backendName: "webgl", kernelFunc: DX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function MX(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { filterSize: r, strides: i, pad: a, dimRoundingMode: c, dataFormat: l } = s, u = [1, 1, 1], d = ts(o.shape, r, i, u, a, c, l), h = new Np(d, "avg", !1); return e.runWebGLProgram(h, [o], "float32") } const FX = { kernelName: ya, backendName: "webgl", kernelFunc: MX };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class VX {
        constructor(t) {
            this.variableNames = ["dy"], this.outputShape = t.inShape; const e = t.filterHeight, s = t.filterWidth, o = t.strideHeight, r = t.strideWidth, i = t.dilationHeight, a = t.dilationWidth, c = t.effectiveFilterHeight, l = t.effectiveFilterWidth, u = c - 1 - t.padInfo.top, d = l - 1 - t.padInfo.left, h = 1 / (e * s); this.userCode = `
      const ivec2 pads = ivec2(${u}, ${d});
      const float avgMultiplier = float(${h});

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];

        ivec2 dyRCCorner = coords.yz - pads;
        int dyRCorner = dyRCCorner.x;
        int dyCCorner = dyRCCorner.y;

        // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;
        for (int wR = 0; wR < ${c};
            wR += ${i}) {
          float dyR = float(dyRCorner + wR) / ${o}.0;

          if (dyR < 0.0 || dyR >= ${t.outHeight}.0 || fract(dyR) > 0.0) {
            continue;
          }
          int idyR = int(dyR);

          for (int wC = 0; wC < ${l};
            wC+= ${a}) {
            float dyC = float(dyCCorner + wC) / ${r}.0;

            if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                fract(dyC) > 0.0) {
              continue;
            }
            int idyC = int(dyC);

            float dyValue = getDy(b, idyR, idyC, d);

            dotProd += dyValue * avgMultiplier;
          }
        }
        setOutput(dotProd);
      }
    `}
    } class zX {
        constructor(t) {
            this.variableNames = ["dy"], this.outputShape = t.inShape; const e = t.filterDepth, s = t.filterHeight, o = t.filterWidth, r = t.strideDepth, i = t.strideHeight, a = t.strideWidth, c = t.dilationDepth, l = t.dilationHeight, u = t.dilationWidth, d = t.effectiveFilterDepth, h = t.effectiveFilterHeight, p = t.effectiveFilterWidth, f = d - 1 - t.padInfo.front, m = h - 1 - t.padInfo.top, g = p - 1 - t.padInfo.left, b = 1 / (e * s * o); this.userCode = `
      const ivec3 pads = ivec3(${f}, ${m}, ${g});
      const float avgMultiplier = float(${b});

      void main() {
        ivec5 coords = getOutputCoords();
        int batch = coords.x;
        int ch = coords.u;

        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
        int dyDCorner = dyCorner.x;
        int dyRCorner = dyCorner.y;
        int dyCCorner = dyCorner.z;

        // Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
        // dx(xD, xR, xC, ch).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;

        for (int wD = 0; wD < ${d};
            wD += ${c}) {
          float dyD = float(dyDCorner + wD) / ${r}.0;

          if (dyD < 0.0 || dyD >= ${t.outDepth}.0 || fract(dyD) > 0.0) {
            continue;
          }
          int idyD = int(dyD);

          for (int wR = 0; wR < ${h};
              wR += ${l}) {
            float dyR = float(dyRCorner + wR) / ${i}.0;

            if (dyR < 0.0 || dyR >= ${t.outHeight}.0 ||
                fract(dyR) > 0.0) {
              continue;
            }
            int idyR = int(dyR);

            for (int wC = 0; wC < ${p};
                wC += ${u}) {
              float dyC = float(dyCCorner + wC) / ${a}.0;

              if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                  fract(dyC) > 0.0) {
                continue;
              }
              int idyC = int(dyC);

              float dyValue = getDy(batch, idyD, idyR, idyC, ch);
              dotProd += dyValue * avgMultiplier;
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function XX(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, i = r, { filterSize: a, strides: c, pad: l, dimRoundingMode: u } = s, d = [1, 1, 1], h = ts(i.shape, a, c, d, l, u), p = new zX(h); return e.runWebGLProgram(p, [o], i.dtype) } const AX = { kernelName: nu, backendName: "webgl", kernelFunc: XX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function OX(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, i = r; qi([o, r], "avgPoolGrad"); const { filterSize: a, strides: c, pad: l } = s, u = hn(i.shape, a, c, 1, l), d = new VX(u); return e.runWebGLProgram(d, [o], i.dtype) } const PX = { kernelName: eu, backendName: "webgl", kernelFunc: OX };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function KX(n) { const { inputs: t, backend: e, attrs: s } = n, { a: o, b: r } = t, { transposeA: i, transposeB: a } = s; return Nl({ a: o, b: r, transposeA: i, transposeB: a, backend: e }) } const ZX = { kernelName: Ia, backendName: "webgl", kernelFunc: KX };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class BX {
        constructor(t, e, s, o, r, i) {
            this.outputShape = [], this.variableNames = ["x", "mean", "variance"], gt(t, e), gt(t, s); let a = "0.0"; o != null && (gt(t, o), this.variableNames.push("offset"), a = "getOffsetAtOutCoords()"); let c = "1.0"; r != null && (gt(t, r), this.variableNames.push("scale"), c = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = `
      void main() {
        float x = getXAtOutCoords();
        float mean = getMeanAtOutCoords();
        float variance = getVarianceAtOutCoords();
        float offset = ${a};
        float scale = ${c};
        float inv = scale * inversesqrt(variance + float(${i}));
        setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class HX {
        constructor(t, e, s, o, r, i) {
            this.packedInputs = !0, this.packedOutput = !0, this.variableNames = ["x", "mean", "variance"], gt(t, e), gt(t, s); let a = "vec4(0.0)"; o != null && (gt(t, o), this.variableNames.push("offset"), a = "getOffsetAtOutCoords()"); let c = "vec4(1.0)"; r != null && (gt(t, r), this.variableNames.push("scale"), c = "getScaleAtOutCoords()"), this.outputShape = t, this.userCode = `
      void main() {
        vec4 offset = ${a};
        vec4 scale = ${c};

        vec4 x = getXAtOutCoords();
        vec4 mean = getMeanAtOutCoords();
        vec4 variance = getVarianceAtOutCoords();

        vec4 inv = scale * inversesqrt(variance + vec4(${i}));

        setOutput((x - mean) * inv + offset);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _X = { kernelName: Ea, backendName: "webgl", kernelFunc: ({ inputs: n, backend: t, attrs: e }) => { const { x: s, mean: o, variance: r, offset: i, scale: a } = n; v(o.shape.length === r.shape.length, () => "Batch normalization gradient requires mean and variance to have equal ranks."), v(i == null || o.shape.length === i.shape.length, () => "Batch normalization gradient requires mean and offset to have equal ranks."), v(a == null || o.shape.length === a.shape.length, () => "Batch normalization gradient requires mean and scale to have equal ranks."); let { varianceEpsilon: c } = e; c == null && (c = .001); const l = [s, o, r]; let u = null; i != null && (u = i.shape, l.push(i)); let d = null; a != null && (d = a.shape, l.push(a)); const h = A().getBool("WEBGL_PACK_NORMALIZATION") ? new HX(s.shape, o.shape, r.shape, u, d, c) : new BX(s.shape, o.shape, r.shape, u, d, c); return t.runWebGLProgram(h, l, l[0].dtype) } };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class UX {
        constructor(t) {
            this.variableNames = ["source"], this.outputShape = t, this.rank = t.length; const e = Xt(this.rank); this.customUniforms = [{ name: "start", arrayIndex: this.rank, type: "int" }]; const s = YX(this.rank); let o; const r = t.map((i, a) => `sourceLoc.${Rp[a]} = start[${a}] + coords.${Rp[a]};`); o = `
        ${e} sourceLoc;
        ${e} coords = getOutputCoords();
        ${r.join(`
`)}
      `, this.userCode = `
      void main() {
        ${o}
        setOutput(getSource(${s}));
      }
    `}
    } const Rp = ["x", "y", "z", "w", "u", "v"]; function YX(n) { if (n === 1) return "sourceLoc"; if (n <= 6) return Rp.slice(0, n).map(t => "sourceLoc." + t).join(","); throw Error(`Slicing for rank ${n} is not yet supported`) }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class QX {
        constructor(t) {
            this.variableNames = ["source"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t, this.rank = t.length, this.customUniforms = [{ name: "start", arrayIndex: this.rank, type: "int" }]; const e = Xt(this.rank), s = De("coords", this.rank), o = De("sourceLoc", this.rank), r = this.rank === 1 ? "sourceLoc" : `vec2(${o.slice(-2).join()})`, i = `getChannel(getSource(${o.join()}), ${r})`, a = `
      result.x = ${i};
      if (++${s[this.rank - 1]} < ${t[this.rank - 1]}) {
        ++${o[this.rank - 1]};
        result.y = ${i};
        --${o[this.rank - 1]};
      }
    `, c = this.rank === 1 ? "" : `
      --${s[this.rank - 1]};
      if (++${s[this.rank - 2]} < ${t[this.rank - 2]}) {
        ++${o[this.rank - 2]};
        result.z = ${i};
        if (++${s[this.rank - 1]} < ${t[this.rank - 1]}) {
          ++${o[this.rank - 1]};
          result.w = ${i};
        }
      }
    `, l = this.rank <= 4 ? `sourceLoc = coords +
            ${e}(${t.map((u, d) => `start[${d}]`).join()});` : t.map((u, d) => `${o[d]} = ${s[d]} + start[${d}];`).join(`
`); this.userCode = `
      void main() {
        ${e} coords = getOutputCoords();
        ${e} sourceLoc;
        ${l}
        vec4 result = vec4(0.);
        ${a}
        ${c}
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JX(n, t, e, s) { const o = s.texData.get(n.dataId), r = s.makeTensorInfo(e, n.dtype), i = s.texData.get(r.dataId); Object.assign(i, o), i.refCount = 1, i.shape = e, i.dtype = n.dtype; let a = Qd(t, ct(n.shape)); o.slice && (a += o.slice.flatOffset), i.slice = { flatOffset: a, origDataId: o.slice && o.slice.origDataId || n.dataId }; const c = s.dataRefCount.get(i.slice.origDataId) || 1; return s.dataRefCount.set(i.slice.origDataId, c + 1), r } function pr(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { begin: r, size: i } = s, [a, c] = Wc(o, r, i); if (_d(o, a, c), Z(c) === 0) return e.makeTensorInfo(c, o.dtype, []); if (e.shouldExecuteOnCPU([o]) || o.dtype === "string") { const d = e.texData.get(o.dataId), h = BV(d.values, a, c, o.shape, o.dtype); return e.makeTensorInfo(c, o.dtype, h) } const { isPacked: l } = e.texData.get(o.dataId), u = Yd(o.shape, a, c); if (l || !u) { const d = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new QX(c) : new UX(c), h = [a]; return e.runWebGLProgram(d, [o], o.dtype, h) } return e.uploadToGPU(o.dataId), JX(o, a, c, e) } const jX = { kernelName: ac, backendName: "webgl", kernelFunc: pr };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qX = { kernelName: Ca, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockShape: r, crops: i } = s; v(o.shape.length <= 4, () => "batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"); const a = r.reduce((x, I) => x * I), c = $i(o.shape, r, a), l = Gi(c.length, r.length), u = Li(o.shape, r, a), d = eh(i, r.length), h = nh(u, i, r.length), p = [], f = et({ inputs: { x: o }, backend: e, attrs: { shape: c } }), m = We({ inputs: { x: f }, backend: e, attrs: { perm: l } }), g = et({ inputs: { x: m }, backend: e, attrs: { shape: u } }), b = pr({ inputs: { x: g }, backend: e, attrs: { begin: d, size: h } }); return p.push(f), p.push(m), p.push(g), p.forEach(x => e.disposeIntermediateTensorInfo(x)), b } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, weights: r } = t, { size: i } = s, a = e.readSync(o.dataId), c = e.readSync(r.dataId), l = r1(a, c, r.dtype, r.shape, i); return e.makeTensorInfo([i], r.dtype, l) } const eA = { kernelName: su, backendName: "webgl", kernelFunc: tA };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nA(n) { const { inputs: t, backend: e } = n, { s0: s, s1: o } = t, r = e.readSync(s.dataId), i = e.readSync(o.dataId), a = gt(Array.from(r), Array.from(i)); return e.makeTensorInfo([a.length], "int32", Int32Array.from(a)) } const sA = { kernelName: df, backendName: "webgl", kernelFunc: nA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const $1 = we({ opSnippet: "return float(a != b);", cpuKernelImpl: FV, dtype: "bool" }), oA = { kernelName: Ya, backendName: "webgl", kernelFunc: $1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ra(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = e.texData.get(s.dataId); return Ye({ inputs: { x: o.complexTensorInfos.real }, backend: e }) } const rA = { kernelName: $u, backendName: "webgl", kernelFunc: ra };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iA = "return float(int(x));"; function aA(n, t) { const e = new Yn(n.shape, iA), s = t.runWebGLProgram(e, [n], "int32"); return { dataId: s.dataId, shape: s.shape, dtype: s.dtype } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $p(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { dtype: r } = s; if (r === "complex64") { if (o.dtype === "complex64") return Ye({ inputs: { x: o }, backend: e }); const i = me(o.shape), a = $p({ inputs: { x: o }, backend: e, attrs: { dtype: "float32" } }), c = Ws({ inputs: { real: a, imag: i }, backend: e }); return i.dispose(), e.disposeIntermediateTensorInfo(a), c } if (o.dtype === "complex64") { const i = ra({ inputs: { input: o }, backend: e }), a = $p({ inputs: { x: i }, backend: e, attrs: { dtype: r } }); return e.disposeIntermediateTensorInfo(i), a } if (!of(o.dtype, r)) { const i = Ye({ inputs: { x: o }, backend: e }); return { dataId: i.dataId, shape: i.shape, dtype: r } } if (e.shouldExecuteOnCPU([o])) { const i = e.texData.get(o.dataId).values, [a, c, l] = gV(i, o.shape, o.dtype, r); return e.makeTensorInfo(a, c, l) } if (r === "int32") return aA(o, e); if (r === "bool") { const i = e.makeTensorInfo([], "bool", xe("bool", 1)), c = $1({ inputs: { a: o, b: i }, backend: e }); return e.disposeIntermediateTensorInfo(i), c } throw new Error(`Error in Cast: failed to cast ${o.dtype} to ${r}`) } const cA = { kernelName: Tr, backendName: "webgl", kernelFunc: $p };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const G1 = "return ceil(x);", lA = Tt({ opSnippet: G1, packedOpSnippet: G1, cpuKernelImpl: bV }), uA = { kernelName: Nr, backendName: "webgl", kernelFunc: lA };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class dA {
        constructor(t) {
            this.variableNames = ["A"], this.customUniforms = [{ name: "minVal", type: "float" }, { name: "maxVal", type: "float" }], this.outputShape = t, this.userCode = `

      void main() {
        float value = getAAtOutCoords();
        if (isnan(value)) {
          setOutput(value);
          return;
        }

        setOutput(clamp(value, minVal, maxVal));
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class hA {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "minVal", type: "float" }, { name: "maxVal", type: "float" }], this.outputShape = t, this.userCode = `
      void main() {
        vec4 value = getAAtOutCoords();

        if (any(isnan(value))) {
          setOutput(value);
          return;
        }

        setOutput(clamp(value, vec4(minVal), vec4(maxVal)));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { clipValueMin: r, clipValueMax: i } = s; let a; A().getBool("WEBGL_PACK_CLIP") ? a = new hA(o.shape) : a = new dA(o.shape); const c = [[r], [i]]; return e.runWebGLProgram(a, [o], o.dtype, c) } const fA = { kernelName: Rr, backendName: "webgl", kernelFunc: pA };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class mA {
        constructor(t) {
            this.variableNames = ["real", "imag"], this.outputShape = t, this.userCode = `
      void main() {
        float re = abs(getRealAtOutCoords());
        float im = abs(getImagAtOutCoords());
        float mx = max(re, im);

        // sadly the length function in glsl is not underflow-safe
        // (at least not on Intel GPUs). So the safe solution is
        // to ensure underflow-safety in all cases.
        setOutput(
          mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))
        );
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function L1(n, t) { return { dataId: t.dataId, dtype: t.dtype, shape: n.shape } } function gA(n) { const { inputs: t, backend: e } = n, { x: s } = t, o = e.texData.get(s.dataId), r = new mA(s.shape), i = [L1(s, o.complexTensorInfos.real), L1(s, o.complexTensorInfos.imag)]; return e.runWebGLProgram(r, i, i[0].dtype) } const bA = { kernelName: wa, backendName: "webgl", kernelFunc: gA };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class xA {
        constructor(t) {
            this.outputShape = [], this.outputShape = On(t, 1), this.variableNames = t.map((i, a) => `T${a}`); const e = new Array(t.length - 1); e[0] = t[0][1]; for (let i = 1; i < e.length; i++)e[i] = e[i - 1] + t[i][1]; const s = [`if (yC < ${e[0]}) setOutput(getT0(yR, yC));`]; for (let i = 1; i < e.length; i++) { const a = e[i - 1]; s.push(`else if (yC < ${e[i]}) setOutput(getT${i}(yR, yC-${a}));`) } const o = e.length, r = e[e.length - 1]; s.push(`else setOutput(getT${o}(yR, yC-${r}));`), this.userCode = `
      void main() {
        ivec2 coords = getOutputCoords();
        int yR = coords.x;
        int yC = coords.y;

        ${s.join(`
        `)}
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class yA {
        constructor(t, e) {
            this.packedInputs = !0, this.packedOutput = !0, this.outputShape = [], this.outputShape = On(t, e); const s = this.outputShape, o = s.length, r = Xt(o), i = De("coords", o), a = ["x", "y", "z", "w", "u", "v"].slice(0, o); this.variableNames = t.map((m, g) => `T${g}`); const c = new Array(t.length - 1); c[0] = t[0][e]; for (let m = 1; m < c.length; m++)c[m] = c[m - 1] + t[m][e]; const l = a[e], u = a.slice(-2), d = a.join(); let h = `if (${l} < ${c[0]}) {
        return getChannel(
            getT0(${d}), vec2(${u.join()}));
        }`; for (let m = 1; m < c.length; m++) {
                const g = c[m - 1]; h += `
        if (${l} < ${c[m]}  && ${l} >= ${c[m - 1]}) {
          return getChannel(
            getT${m}(${$l(a, l, g)}),
            vec2(${$l(u, l, g)}));
        }`} const p = c.length, f = c[c.length - 1]; h += `
        return getChannel(
          getT${p}(${$l(a, l, f)}),
          vec2(${$l(u, l, f)}));`, this.userCode = `
      float getValue(${a.map(m => "int " + m)}) {
        ${h}
      }

      void main() {
        ${r} coords = getOutputCoords();
        vec4 result = vec4(getValue(${i}), 0., 0., 0.);

        ${i[o - 1]} = ${i[o - 1]} + 1;
        if (${i[o - 1]} < ${s[o - 1]}) {
          result.g = getValue(${i});
        }

        ${i[o - 2]} = ${i[o - 2]} + 1;
        if (${i[o - 2]} < ${s[o - 2]}) {
          result.a = getValue(${i});
        }

        ${i[o - 1]} = ${i[o - 1]} - 1;
        if (${i[o - 2]} < ${s[o - 2]} &&
            ${i[o - 1]} < ${s[o - 1]}) {
          result.b = getValue(${i});
        }
        setOutput(result);
      }
    `}
    } function $l(n, t, e) { const s = n.indexOf(t); return n.map((r, i) => i === s ? `${r} - ${e}` : r).join() }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gl(n) { const { inputs: t, backend: e } = n, { input: s } = t, o = e.texData.get(s.dataId); return Ye({ inputs: { x: o.complexTensorInfos.imag }, backend: e }) } const IA = { kernelName: Cu, backendName: "webgl", kernelFunc: Gl };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ia(n, t, e) { const s = n[0].dtype; if (s === "complex64") { const p = n.map(x => ra({ inputs: { input: x }, backend: e })), f = n.map(x => Gl({ inputs: { input: x }, backend: e })), m = ia(p, t, e), g = ia(f, t, e), b = Ws({ inputs: { real: m, imag: g }, backend: e }); return p.forEach(x => e.disposeIntermediateTensorInfo(x)), f.forEach(x => e.disposeIntermediateTensorInfo(x)), e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(g), b } let o = e.shouldExecuteOnCPU(n); if (s === "string" && (o = !0), o) { const p = n.map(y => { const w = [-1, Z(y.shape.slice(t))]; return et({ inputs: { x: y }, backend: e, attrs: { shape: w } }) }), f = p.map(y => ({ vals: e.readSync(y.dataId), shape: y.shape })), m = On(p.map(y => y.shape), 1), g = p[0].shape[0] === 1, b = xV(f, m, s, g), x = On(n.map(y => y.shape), t), I = e.makeTensorInfo(x, s, b); return p.forEach(y => e.disposeIntermediateTensorInfo(y)), I } const r = n.filter(p => Z(p.shape) > 0), i = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") && r[0].shape.length > 1; if (r.length === 1) { const p = i ? new Yn(n[0].shape, Es) : new Ds(n[0].shape, Es); return e.runWebGLProgram(p, n, s) } const a = A().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER"); if (r.length > a) { const p = []; for (let m = 0; m < r.length; m += a) { const g = r.slice(m, m + a); p.push(ia(g, t, e)) } const f = ia(p, t, e); for (const m of p) e.disposeIntermediateTensorInfo(m); return f } if (i) { const p = new yA(r.map(f => f.shape), t); return e.runWebGLProgram(p, r, s) } const { tensors2D: c, outShape: l } = CA(r, t, e), u = new xA(c.map(p => p.shape)), d = e.runWebGLProgram(u, c, s); c.forEach(p => e.disposeIntermediateTensorInfo(p)); const h = et({ inputs: { x: d }, attrs: { shape: l }, backend: e }); return e.disposeIntermediateTensorInfo(d), h } function CA(n, t, e) { const s = On(n.map(r => r.shape), t); return { tensors2D: n.map(r => et({ inputs: { x: r }, attrs: { shape: [-1, Z(r.shape.slice(t))] }, backend: e })), outShape: s } }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function E1(n) { const { inputs: t, backend: e, attrs: s } = n, { axis: o } = s, r = It(o, t[0].shape)[0], i = t.map(l => l.shape); jd(i, r); const a = On(t.map(l => l.shape), r); if (Z(a) === 0) return e.makeTensorInfo(a, t[0].dtype, []); const c = t.filter(l => Z(l.shape) > 0); return c.length === 1 ? Ye({ inputs: { x: c[0] }, backend: e }) : ia(c, r, e) } const wA = { kernelName: va, backendName: "webgl", kernelFunc: E1 };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class D1 {
        constructor(t, e = !1, s = null, o = !1, r = !1) {
            this.variableNames = ["x", "W"], this.outputShape = t.outShape; const i = t.padInfo.top, a = t.padInfo.left, c = t.strideHeight, l = t.strideWidth, u = t.dilationHeight, d = t.dilationWidth, h = t.filterHeight, p = t.filterWidth, f = Math.floor(t.inChannels / 4) * 4, m = t.inChannels % 4, g = t.dataFormat === "channelsLast", b = g ? 1 : 2, x = g ? 2 : 3, I = g ? 3 : 1; let y = "", C = ""; s && (o ? y = `float activation(float a) {
          float b = getPreluActivationWeightsAtOutCoords();
          ${s}
        }`: r ? y = `float activation(float a) {
          float b = getLeakyreluAlphaAtOutCoords();
          ${s}
        }`: y = `
          float activation(float x) {
            ${s}
          }
        `, C = "result = activation(result);"); const w = e ? "result += getBiasAtOutCoords();" : ""; e && this.variableNames.push("bias"), o && this.variableNames.push("preluActivationWeights"), r && this.variableNames.push("leakyreluAlpha"), this.userCode = `
      ${y}

      const ivec2 strides = ivec2(${c}, ${l});
      const ivec2 pads = ivec2(${i}, ${a});

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords[0];
        int d2 = coords[${I}];

        ivec2 xRCCorner =
            ivec2(coords[${b}], coords[${x}]) * strides - pads;
        int xRCorner = xRCCorner.x;
        int xCCorner = xRCCorner.y;

        // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;
        for (int wR = 0; wR < ${h}; wR++) {
          int xR = xRCorner + wR * ${u};

          if (xR < 0 || xR >= ${t.inHeight}) {
            continue;
          }

          for (int wC = 0; wC < ${p}; wC++) {
            int xC = xCCorner + wC * ${d};

            if (xC < 0 || xC >= ${t.inWidth}) {
              continue;
            }

            for (int d1 = 0; d1 < ${f}; d1 += 4) {
              vec4 wValues = vec4(
                getW(wR, wC, d1, d2),
                getW(wR, wC, d1 + 1, d2),
                getW(wR, wC, d1 + 2, d2),
                getW(wR, wC, d1 + 3, d2)
              );

              if (${g}) {
                vec4 xValues = vec4(
                  getX(batch, xR, xC, d1),
                  getX(batch, xR, xC, d1 + 1),
                  getX(batch, xR, xC, d1 + 2),
                  getX(batch, xR, xC, d1 + 3)
                );
                dotProd += dot(xValues, wValues);
              } else {
                vec4 xValues = vec4(
                  getX(batch, d1, xR, xC),
                  getX(batch, d1 + 1, xR, xC),
                  getX(batch, d1 + 2, xR, xC),
                  getX(batch, d1 + 3, xR, xC)
                );
                dotProd += dot(xValues, wValues);
              }
            }

            if (${m === 1}) {

              if (${g}) {
                dotProd +=
                    getX(batch, xR, xC, ${f}) *
                    getW(wR, wC, ${f}, d2);
              } else {
                dotProd +=
                    getX(batch, ${f}, xR, xC) *
                    getW(wR, wC, ${f}, d2);
              }

            } else if (${m === 2}) {
              vec2 wValues = vec2(
                getW(wR, wC, ${f}, d2),
                getW(wR, wC, ${f} + 1, d2)
              );

              if (${g}) {
                vec2 xValues = vec2(
                  getX(batch, xR, xC, ${f}),
                  getX(batch, xR, xC, ${f} + 1)
                );
                dotProd += dot(xValues, wValues);
              } else {
                vec2 xValues = vec2(
                  getX(batch, ${f}, xR, xC),
                  getX(batch, ${f} + 1, xR, xC)
                );
                dotProd += dot(xValues, wValues);
              }

            } else if (${m === 3}) {
              vec3 wValues = vec3(
                getW(wR, wC, ${f}, d2),
                getW(wR, wC, ${f} + 1, d2),
                getW(wR, wC, ${f} + 2, d2)
              );

              if (${g}) {
                vec3 xValues = vec3(
                  getX(batch, xR, xC, ${f}),
                  getX(batch, xR, xC, ${f} + 1),
                  getX(batch, xR, xC, ${f} + 2)
                );
                dotProd += dot(xValues, wValues);
              } else {
                vec3 xValues = vec3(
                  getX(batch, ${f}, xR, xC),
                  getX(batch, ${f} + 1, xR, xC),
                  getX(batch, ${f} + 2, xR, xC)
                );
                dotProd += dot(xValues, wValues);
              }

            }
          }
        }

        float result = dotProd;
        ${w}
        ${C}
        setOutput(result);
      }
    `}
    } class vA {
        constructor(t) {
            this.variableNames = ["x", "W"], this.outputShape = t.outShape; const e = t.padInfo.front, s = t.padInfo.top, o = t.padInfo.left, r = t.strideDepth, i = t.strideHeight, a = t.strideWidth, c = t.dilationDepth, l = t.dilationHeight, u = t.dilationWidth, d = t.filterDepth, h = t.filterHeight, p = t.filterWidth, f = Math.floor(t.inChannels / 4) * 4, m = t.inChannels % 4; this.userCode = `
      const ivec3 strides = ivec3(${r}, ${i}, ${a});
      const ivec3 pads = ivec3(${e}, ${s}, ${o});

      void main() {
        ivec5 coords = getOutputCoords();
        int batch = coords.x;
        int d2 = coords.u;

        ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;
        int xFCorner = xFRCCorner.x;
        int xRCorner = xFRCCorner.y;
        int xCCorner = xFRCCorner.z;

        // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get
        // y(yF, yR, yC, d2). ? = to be determined. : = across all
        // values in that axis.
        float dotProd = 0.0;
        for (int wF = 0; wF < ${d}; wF++) {
          int xF = xFCorner + wF * ${c};

          if (xF < 0 || xF >= ${t.inDepth}) {
            continue;
          }

          for (int wR = 0; wR < ${h}; wR++) {
            int xR = xRCorner + wR * ${l};

            if (xR < 0 || xR >= ${t.inHeight}) {
              continue;
            }

            for (int wC = 0; wC < ${p}; wC++) {
              int xC = xCCorner + wC * ${u};

              if (xC < 0 || xC >= ${t.inWidth}) {
                continue;
              }

              for (int d1 = 0; d1 < ${f}; d1 += 4) {
                vec4 xValues = vec4(
                  getX(batch, xF, xR, xC, d1),
                  getX(batch, xF, xR, xC, d1 + 1),
                  getX(batch, xF, xR, xC, d1 + 2),
                  getX(batch, xF, xR, xC, d1 + 3)
                );
                vec4 wValues = vec4(
                  getW(wF, wR, wC, d1, d2),
                  getW(wF, wR, wC, d1 + 1, d2),
                  getW(wF, wR, wC, d1 + 2, d2),
                  getW(wF, wR, wC, d1 + 3, d2)
                );

                dotProd += dot(xValues, wValues);
              }

              if (${m === 1}) {
                dotProd +=
                  getX(batch, xF, xR, xC, ${f}) *
                  getW(wF, wR, wC, ${f}, d2);
              } else if (${m === 2}) {
                vec2 xValues = vec2(
                  getX(batch, xF, xR, xC, ${f}),
                  getX(batch, xF, xR, xC, ${f} + 1)
                );
                vec2 wValues = vec2(
                  getW(wF, wR, wC, ${f}, d2),
                  getW(wF, wR, wC, ${f} + 1, d2)
                );
                dotProd += dot(xValues, wValues);
              } else if (${m === 3}) {
                vec3 xValues = vec3(
                  getX(batch, xF, xR, xC, ${f}),
                  getX(batch, xF, xR, xC, ${f} + 1),
                  getX(batch, xF, xR, xC, ${f} + 2)
                );
                vec3 wValues = vec3(
                  getW(wF, wR, wC, ${f}, d2),
                  getW(wF, wR, wC, ${f} + 1, d2),
                  getW(wF, wR, wC, ${f} + 2, d2)
                );
                dotProd += dot(xValues, wValues);
              }
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class W1 {
        constructor(t, e = !1, s = null, o = !1, r = !1) {
            this.variableNames = ["x", "W"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "pads", type: "ivec2" }, { name: "strides", type: "ivec2" }, { name: "dilations", type: "ivec2" }, { name: "inDims", type: "ivec2" }], this.outputShape = t.outShape, this.enableShapeUniforms = Ee(this.outputShape.length); const i = t.padInfo.left, a = t.strideWidth, c = t.dilationWidth, l = t.filterHeight, u = t.filterWidth, d = u; let h = `
       int xR; int xC; int xCOffset;
       vec4 wTexel; vec4 previous; vec4 final;`; for (let g = 0; g < u; g++)h += `
           vec4 xTexelC${g * 2};
           int xTexelC${g * 2}Ready;
           vec4 xTexelC${g * 2 + 1};
           int xTexelC${g * 2 + 1}Ready;
           vec4 xC${g};`; h += `
     for (int r = 0; r < ${l}; r++) {
      for (int d1 = 0; d1 < ${t.inChannels}; d1 += 2) {
       `; for (let g = 0; g < u; g++)h += `
           xTexelC${g * 2} = vec4(0.0);
           xTexelC${g * 2}Ready = 0;
           xTexelC${g * 2 + 1} = vec4(0.0);
           xTexelC${g * 2 + 1}Ready = 0;
           xC${g} = vec4(0.0);`; h += `
         xR = xRCorner + r * dilations[0];
         if (xR >=0 && xR < inDims[0]) {
       `; for (let g = 0; g < (d + 1) / 2; g++) {
                const b = g * 2; if (h += `
           xC = xCCorner + ${b * c};
           `, a === 1) {
                    if (b < u && (i % 2 === 1 ? (h += `
                 xCOffset = xC + 1;
                 if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${b}Ready == 0) {
                   xTexelC${b} = getX(batch, xR, xCOffset, d1);

                   // Need to manually clear unused channels in case
                   // we're reading from recycled texture.
                   if (xCOffset + 1 >= inDims[1]) {
                     xTexelC${b}.zw = vec2(0.0);
                   }
                   xTexelC${b}Ready = 1;
                 }
               `, c === 1 && b > 0 ? h += `
                 xC${b} = vec4(xTexelC${b - 2}.zw, xTexelC${b}.xy);
                 `: h += `
                   xCOffset = xC + 1 - 2;

                   if (xCOffset >= 0 && xCOffset < inDims[1]) {
                     previous = getX(batch, xR, xCOffset, d1);

                     // Need to manually clear unused channels in case
                     // we're reading from recycled texture.
                     if (xCOffset + 1 >= inDims[1]) {
                       previous.zw = vec2(0.0);
                     }

                     xC${b} = vec4(previous.zw, xTexelC${b}.xy);
                   } else {
                     xC${b} = vec4(0.0, 0.0, xTexelC${b}.xy);
                   }
                   `) : h += `
                 if (xC >= 0 && xC < inDims[1] && xTexelC${b}Ready == 0) {
                   xTexelC${b} = getX(batch, xR, xC, d1);
                   if (xC + 1 >= inDims[1]) {
                     xTexelC${b}.zw = vec2(0.0);
                   }
                   xTexelC${b}Ready = 1;
                 }

                 xC${b} = xTexelC${b};
                 `, b + 1 < u)) {
                        const x = i % 2 === 0 ? Ol(c) : c; c % 2 === 0 && i % 2 === 1 || c % 2 !== 0 && i % 2 !== 1 ? (h += `
                   xCOffset = xC + imod(pads[1], 2) + ${x};

                   if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${b + 1}Ready == 0) {
                     xTexelC${b + 1} = getX(batch, xR, xCOffset, d1);

                     // Need to manually clear unused channels in case
                     // we're reading from recycled texture.
                     if (xCOffset + 1 >= inDims[1]) {
                       xTexelC${b + 1}.zw = vec2(0.0);
                     }
                     xTexelC${b + 1}Ready = 1;
                   }
                   `, c > 1 ? h += `
                     xCOffset -= 2;
                     if (xCOffset >= 0 && xCOffset < inDims[1]) {
                      previous = getX(batch, xR, xCOffset, d1);
                      xC${b + 1} = vec4(previous.zw, xTexelC${b + 1}.xy);
                     } else {
                      xC${b + 1} = vec4(0.0, 0.0, xTexelC${b + 1}.xy);
                     }
                     `: h += `
                     xC${b + 1} = vec4(xTexelC${b}.zw, xTexelC${b + 1}.xy);
                     `) : x === 1 ? h += `
                     xC${b + 1} = xTexelC${b};
                     `: h += `
                     xCOffset = xC + ${x};

                     if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${b + 1}Ready == 0) {
                       xTexelC${b + 1} = getX(batch, xR, xCOffset, d1);
                       if (xCOffset + 1 >= inDims[1]) {
                         xTexelC${b + 1}.zw = vec2(0.0);
                       }
                       xTexelC${b + 1}Ready = 1;
                     }

                     xC${b + 1} = xTexelC${b + 1};
                     `}
                } else b < u && (i % 2 === 1 ? (h += `
                 xCOffset = xC + 1 - strides[1];
                 if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${b}Ready == 0) {
                   xTexelC${b} = getX(batch, xR, xCOffset, d1);
                   // Need to manually clear unused channels in case
                   // we're reading from recycled texture.
                   if (xCOffset + 1 >= inDims[1]) {
                     xTexelC${b}.zw = vec2(0.0);
                   }
                   xTexelC${b}Ready = 1;
                 }

                 if(xC + 1 >= 0 && xC + 1 < inDims[1] && xTexelC${b + 1}Ready == 0) {
                   xTexelC${b + 1} = getX(batch, xR, xC + 1, d1);
                   // Need to manually clear unused channels in case
                   // we're reading from recycled texture.
                   if (xC + 2 >= inDims[1]) {
                     xTexelC${b + 1}.zw = vec2(0.0);
                   }
                   xTexelC${b + 1}Ready = 1;
                 }

                 xC${b} = vec4(xTexelC${b}.zw, xTexelC${b + 1}.zw);
               `, b + 1 < u && (h += `
                   final = vec4(0.0);
                   xCOffset = xC + 1 + strides[1];
                   if(xCOffset >= 0 && xCOffset < inDims[1]) {
                     final = getX(batch, xR, xCOffset, d1);
                   }
                   xC${b + 1} = vec4(xTexelC${b + 1}.xy, final.xy);
                 `)) : (h += `
                 if(xC >= 0 && xC < inDims[1] && xTexelC${b}Ready == 0) {
                   xTexelC${b} = getX(batch, xR, xC, d1);
                   if (xC + 1 >= inDims[1]) {
                     xTexelC${b}.zw = vec2(0.0);
                   }
                   xTexelC${b}Ready = 1;
                 }

                 xCOffset = xC + strides[1];
                 if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${b + 1}Ready == 0) {
                   xTexelC${b + 1} = getX(batch, xR, xCOffset, d1);
                   if (xCOffset + 1 >= inDims[1]) {
                     xTexelC${b + 1}.zw = vec2(0.);
                   }
                   xTexelC${b + 1}Ready = 1;
                 }

                 xC${b} = vec4(
                   xTexelC${b}.xy, xTexelC${b + 1}.xy);
               `, b + 1 < u && (h += `
                   xC${b + 1} = vec4(xTexelC${b}.zw, xTexelC${b + 1}.zw);
                 `))); b < u && (h += `
             wTexel = getW(r, ${b}, d1, d2);
             dotProd += xC${b}.xxzz * vec4(wTexel.xy, wTexel.xy);
             if(d1 + 1 < ${t.inChannels}) {
               dotProd += xC${b}.yyww * vec4(wTexel.zw, wTexel.zw);
             }
           `, b + 1 < u && (h += `
               wTexel = getW(r, ${b + 1}, d1, d2);
               dotProd += xC${b + 1}.xxzz * vec4(wTexel.xy, wTexel.xy);
               if(d1 + 1 < ${t.inChannels}) {
                 dotProd += xC${b + 1}.yyww * vec4(wTexel.zw, wTexel.zw);
               }
             `))
            } h += `
     }
   `, h += `
     }
   `, h += `
     }
   `; let p = "", f = ""; s && (o ? p = `vec4 activation(vec4 a) {
           vec4 b = getPreluActivationWeightsAtOutCoords();
           ${s}
         }`: r ? p = `vec4 activation(vec4 a) {
           vec4 b = getLeakyreluAlphaAtOutCoords();
           ${s}
         }`: p = `vec4 activation(vec4 x) {
           ${s}
         }`, f = "result = activation(result);"); const m = e ? "result += getBiasAtOutCoords();" : ""; e && this.variableNames.push("bias"), o && this.variableNames.push("preluActivationWeights"), r && this.variableNames.push("leakyreluAlpha"), this.userCode = `
       ${p}

       void main() {
         ivec4 coords = getOutputCoords();
         int batch = coords.x;
         ivec2 xRCCorner = coords.yz * strides - pads;
         int d2 = coords.w;
         int xRCorner = xRCCorner.x;
         int xCCorner = xRCCorner.y;

         //intialize dotProd with a small epsilon seems to reduce GPU accuracy loss.
         vec4 dotProd = vec4(0.000000000000001);

         ${h}

         vec4 result = dotProd - vec4(0.000000000000001);
         ${m}
         ${f}
         setOutput(result);
       }
     `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class SA {
        constructor(t, e) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec4" }, { name: "pad", type: "ivec2" }, { name: "stride", type: "ivec2" }, { name: "dilation", type: "ivec2" }, { name: "inChannels", type: "int" }, { name: "itemsPerBlockRow", type: "int" }, { name: "outWidth", type: "int" }], this.outputShape = t, this.enableShapeUniforms = Ee(this.outputShape.length); const { dataFormat: s } = e, o = Le(), r = s === "channelsLast", i = r ? 1 : 2, a = r ? 2 : 3, c = this.enableShapeUniforms ? "if(blockIndex < outShape[2] && pos < outShape[1]) {" : `if(blockIndex < ${t[2]} && pos < ${t[1]}) {`; let l = ""; for (let u = 0; u <= 1; u++)for (let d = 0; d <= 1; d++)l += `
          blockIndex = rc.z + ${d};
          pos = rc.y + ${u};

          ${c}
            offsetY = int(blockIndex / outWidth) * stride[0] - pad[0];
            d0 = offsetY + dilation[0] * (pos / itemsPerBlockRow);

            if(d0 < inputShape[${i}] && d0 >= 0) {
              // Use custom imod instead mod. On Intel GPU, mod may generate
              // unexpected value.
              // https://github.com/tensorflow/tfjs/issues/5447
              offsetX = imod(blockIndex, outWidth) * stride[1] - pad[1];
              d1 = offsetX + dilation[1] * (imod(pos, itemsPerBlockRow) /
                  inChannels);

              if(d1 < inputShape[${a}] && d1 >= 0) {

                ch = imod(pos, inChannels);

                if (${r}) {
                  innerDims = vec2(d1, ch);
                  result[${u * 2 + d}] = getChannel(
                    getA(rc.x, d0, int(innerDims.x),
                    int(innerDims.y)), innerDims);
                } else {
                  innerDims = vec2(d0, d1);
                  result[${u * 2 + d}] = getChannel(
                    getA(rc.x, ch, int(innerDims.x),
                    int(innerDims.y)), innerDims);
                }
              }
            }
          }
        `; this.userCode = `
      void main() {
        ivec3 rc = getOutputCoords();

        vec4 result = vec4(0);

        int blockIndex, pos, offsetY, d0, offsetX, d1, ch;
        vec2 innerDims;

        ${l}

        ${o.output} = result;
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Ll(n, t) { const e = n.length; return e >= 3 ? t ? [...n.slice(0, -3), n[e - 3] * n[e - 2], n[e - 1]] : [...n.slice(0, -3), n[e - 3], n[e - 2] * n[e - 1]] : !t && e === 1 && n[0] > 1 ? [n[0], 1] : null } function M1({ x: n, filter: t, convInfo: e, backend: s, bias: o = null, preluActivationWeights: r = null, leakyreluAlpha: i = 0, activation: a = null }) { const c = n.shape, l = s.texData.get(n.dataId), u = e.inChannels, d = c[0] * c[1] * c[2], h = e.outChannels, p = e.dataFormat === "channelsLast", f = !1, m = !1; let g; const b = []; if (r != null) { const y = Ll(r.shape, p); y != null && (r = et({ inputs: { x: r }, backend: s, attrs: { shape: y } }), b.push(r)) } if (o != null) { const y = Ll(o.shape, p); y != null && (o = et({ inputs: { x: o }, backend: s, attrs: { shape: y } }), b.push(o)) } if (!((d === 1 || h === 1) && u > v1) && l.isPacked && p && l.texture != null && c[2] % 2 !== 0 && Rt(l.shape.slice(-3), c.slice(-3))) { const y = c[0] * c[1] * (c[2] + 1), C = { dataId: n.dataId, shape: [1, y, e.inChannels], dtype: n.dtype }, w = l.shape; l.shape = l.shape.slice(), l.shape[l.shape.length - 2]++, v(Cl(l.shape, C.shape), () => `packed reshape ${l.shape} to ${C.shape} isn't free`); const k = et({ inputs: { x: t }, backend: s, attrs: { shape: [1, e.inChannels, e.outChannels] } }); b.push(k); const S = Nl({ a: C, b: k, backend: s, transposeA: f, transposeB: m, bias: o, activation: a, preluActivationWeights: r, leakyreluAlpha: i }), T = s.texData.get(S.dataId); v(T.isPacked, () => "batchMatMul result is expected to be packed"), l.shape = w, T.shape = e.outShape, g = Ye({ inputs: { x: S }, backend: s }), g.shape = e.outShape, b.push(S) } else { const y = e.outHeight * e.outWidth, C = et({ inputs: { x: n }, backend: s, attrs: { shape: p ? [e.batchSize, y, e.inChannels] : [e.batchSize, e.inChannels, y] } }), w = et({ inputs: { x: t }, backend: s, attrs: { shape: [1, e.inChannels, e.outChannels] } }), k = Nl({ a: p ? C : w, b: p ? w : C, transposeA: !p, transposeB: m, backend: s, bias: o, activation: a, preluActivationWeights: r, leakyreluAlpha: i }); g = et({ inputs: { x: k }, backend: s, attrs: { shape: e.outShape } }), b.push(C), b.push(w), b.push(k) } for (const y of b) s.disposeIntermediateTensorInfo(y); return g } function F1({ x: n, filter: t, convInfo: e, backend: s, bias: o = null, preluActivationWeights: r = null, leakyreluAlpha: i = 0, activation: a = null }) { const { filterWidth: c, filterHeight: l, inChannels: u, outWidth: d, outHeight: h, dataFormat: p } = e, f = p === "channelsLast", m = c * l * u, g = h * d, b = [e.batchSize, m, g], x = !0, I = !1, y = []; if (r != null) { const K = Ll(r.shape, f); K != null && (r = et({ inputs: { x: r }, backend: s, attrs: { shape: K } }), y.push(r)) } if (o != null) { const K = Ll(o.shape, f); K != null && (o = et({ inputs: { x: o }, backend: s, attrs: { shape: K } }), y.push(o)) } const C = et({ inputs: { x: t }, backend: s, attrs: { shape: [1, m, Z(t.shape) / m] } }); y.push(C); const w = new SA(b, e), k = [n.shape, [e.padInfo.top, e.padInfo.left], [e.strideHeight, e.strideWidth], [e.dilationHeight, e.dilationWidth], [e.inChannels], [e.filterWidth * e.inChannels], [e.outWidth]], S = s.runWebGLProgram(w, [n], "float32", k), T = et({ inputs: { x: S }, backend: s, attrs: { shape: b } }); y.push(S), y.push(T); const R = o != null, G = r != null, F = a === "leakyrelu", V = a ? sa(a, !0) : null, z = new x1(f ? T.shape : C.shape, f ? C.shape : T.shape, f ? [e.batchSize, g, e.outChannels] : [e.batchSize, e.outChannels, g], x, I, R, V, G, F), X = f ? [T, C] : [C, T]; if (o && X.push(o), G && X.push(r), F) { const K = s.makeTensorInfo([], "float32", ps(i, "float32")); X.push(K), y.push(K) } const O = s.runWebGLProgram(z, X, "float32"), B = et({ inputs: { x: O }, backend: s, attrs: { shape: e.outShape } }); y.push(O); for (const K of y) s.disposeIntermediateTensorInfo(K); return B }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dataFormat: c, dilations: l, dimRoundingMode: u } = s, d = es(c), h = ye(o.shape, r.shape, i, l, a, u, !1, d); let p; if (h.filterHeight === 1 && h.filterWidth === 1 && h.dilationHeight === 1 && h.dilationWidth === 1 && h.strideHeight === 1 && h.strideWidth === 1 && (h.padInfo.type === "SAME" || h.padInfo.type === "VALID")) p = M1({ x: o, filter: r, convInfo: h, backend: e }); else if (h.strideWidth <= 2 && d === "channelsLast" && A().getBool("WEBGL_EXP_CONV")) { const m = new W1(h), g = [[h.padInfo.top, h.padInfo.left], [h.strideHeight, h.strideWidth], [h.dilationHeight, h.dilationWidth], [h.inHeight, h.inWidth]]; p = e.runWebGLProgram(m, [o, r], "float32", g) } else if (A().getBool("WEBGL_CONV_IM2COL")) p = F1({ x: o, filter: r, convInfo: h, backend: e }); else { const m = new D1(h); p = e.runWebGLProgram(m, [o, r], "float32") } const f = et({ inputs: { x: p }, backend: e, attrs: { shape: h.outShape } }); return e.disposeIntermediateTensorInfo(p), f } const TA = { kernelName: Sa, backendName: "webgl", kernelFunc: kA };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class NA {
        constructor(t) {
            this.variableNames = ["x", "dy"], this.outputShape = t.filterShape; const e = t.strideHeight, s = t.strideWidth, o = t.padInfo.top, r = t.padInfo.left, i = t.dataFormat === "channelsLast"; this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int wR = coords.x;
        int wC = coords.y;
        int d1 = coords.z;
        int d2 = coords.w;

        // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;

        for (int b = 0; b < ${t.batchSize}; b++) {
          for (int yR = 0; yR < ${t.outHeight}; yR++) {
            int xR = wR + yR * ${e} - ${o};

            if (xR < 0 || xR >= ${t.inHeight}) {
              continue;
            }

            for (int yC = 0; yC < ${t.outWidth}; yC++) {
              int xC = wC + yC * ${s} - ${r};

              if (xC < 0 || xC >= ${t.inWidth}) {
                continue;
              }

              if (${i}) {
                float dyValue = getDy(b, yR, yC, d2);
                float xValue = getX(b, xR, xC, d1);
                dotProd += (xValue * dyValue);
              } else {
                float dyValue = getDy(b, d2, yR, yC);
                float xValue = getX(b, d1, xR, xC);
                dotProd += (xValue * dyValue);
              }

            }
          }
        }
        setOutput(dotProd);
      }
    `}
    } class RA {
        constructor(t) {
            this.variableNames = ["dy", "W"], this.outputShape = t.inShape; const e = t.filterHeight, s = t.filterWidth, o = t.strideHeight, r = t.strideWidth, i = t.dataFormat === "channelsLast", a = e - 1 - t.padInfo.top, c = s - 1 - t.padInfo.left, l = i ? 1 : 2, u = i ? 2 : 3, d = i ? 3 : 1; this.userCode = `
      const ivec2 pads = ivec2(${a}, ${c});

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords[0];
        int d1 = coords[${d}];

        ivec2 dyCorner = ivec2(coords[${l}], coords[${u}]) - pads;
        int dyRCorner = dyCorner.x;
        int dyCCorner = dyCorner.y;

        // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;
        for (int wR = 0; wR < ${e}; wR++) {
          float dyR = float(dyRCorner + wR) / ${o}.0;

          if (dyR < 0.0 || dyR >= ${t.outHeight}.0 || fract(dyR) > 0.0) {
            continue;
          }
          int idyR = int(dyR);

          int wRPerm = ${e} - 1 - wR;

          for (int wC = 0; wC < ${s}; wC++) {
            float dyC = float(dyCCorner + wC) / ${r}.0;

            if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                fract(dyC) > 0.0) {
              continue;
            }
            int idyC = int(dyC);

            int wCPerm = ${s} - 1 - wC;

            for (int d2 = 0; d2 < ${t.outChannels}; d2++) {

              if (${i}) {
                float xValue = getDy(batch, idyR, idyC, d2);
                float wValue = getW(wRPerm, wCPerm, d1, d2);
                dotProd += xValue * wValue;
              } else {
                float xValue = getDy(batch, d2, idyR, idyC);
                float wValue = getW(wRPerm, wCPerm, d1, d2);
                dotProd += xValue * wValue;
              }

            }
          }
        }
        setOutput(dotProd);
      }
    `}
    } class $A {
        constructor(t) {
            this.variableNames = ["x", "dy"], this.outputShape = t.filterShape; const e = t.strideDepth, s = t.strideHeight, o = t.strideWidth, r = t.padInfo.front, i = t.padInfo.top, a = t.padInfo.left; this.userCode = `
      void main() {
        ivec5 coords = getOutputCoords();
        int wF = coords.x;
        int wR = coords.y;
        int wC = coords.z;
        int d1 = coords.w;
        int d2 = coords.u;

        float dotProd = 0.0;

        for (int b = 0; b < ${t.batchSize}; b++) {
          for (int yF = 0; yF < ${t.outDepth}; yF++) {
            int xF = wF + yF * ${e} - ${r};

            if (xF < 0 || xF >= ${t.inDepth}) {
              continue;
            }

            for (int yR = 0; yR < ${t.outHeight}; yR++) {
              int xR = wR + yR * ${s} - ${i};

              if (xR < 0 || xR >= ${t.inHeight}) {
                continue;
              }

              for (int yC = 0; yC < ${t.outWidth}; yC++) {
                int xC = wC + yC * ${o} - ${a};

                if (xC < 0 || xC >= ${t.inWidth}) {
                  continue;
                }

                float dyValue = getDy(b, yF, yR, yC, d2);
                float xValue = getX(b, xF, xR, xC, d1);
                dotProd += (xValue * dyValue);
              }
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    } class GA {
        constructor(t) {
            this.variableNames = ["dy", "W"], this.outputShape = t.inShape; const e = t.filterDepth, s = t.filterHeight, o = t.filterWidth, r = t.strideDepth, i = t.strideHeight, a = t.strideWidth, c = e - 1 - t.padInfo.front, l = s - 1 - t.padInfo.top, u = o - 1 - t.padInfo.left; this.userCode = `
      const ivec3 pads = ivec3(${c}, ${l}, ${u});

      void main() {
        ivec5 coords = getOutputCoords();
        int batch = coords.x;
        int d1 = coords.u;


        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
        int dyFCorner = dyCorner.x;
        int dyRCorner = dyCorner.y;
        int dyCCorner = dyCorner.z;

        float dotProd = 0.0;
        for (int wF = 0; wF < ${e}; wF++) {
          float dyF = float(dyFCorner + wF) / ${r}.0;

          if (dyF < 0.0 || dyF >= ${t.outDepth}.0 || fract(dyF) > 0.0) {
            continue;
          }
          int idyF = int(dyF);

          int wFPerm = ${e} - 1 - wF;

          for (int wR = 0; wR < ${s}; wR++) {
            float dyR = float(dyRCorner + wR) / ${i}.0;

            if (dyR < 0.0 || dyR >= ${t.outHeight}.0 ||
              fract(dyR) > 0.0) {
              continue;
            }
            int idyR = int(dyR);

            int wRPerm = ${s} - 1 - wR;

            for (int wC = 0; wC < ${o}; wC++) {
              float dyC = float(dyCCorner + wC) / ${a}.0;

              if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                  fract(dyC) > 0.0) {
                continue;
              }
              int idyC = int(dyC);

              int wCPerm = ${o} - 1 - wC;

              for (int d2 = 0; d2 < ${t.outChannels}; d2++) {
                float xValue = getDy(batch, idyF, idyR, idyC, d2);
                float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);
                dotProd += xValue * wValue;
              }
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function LA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, pad: a, dataFormat: c, dimRoundingMode: l, filterShape: u } = s, d = es(c), h = ye(o.shape, u, i, 1, a, l, !1, d), p = new NA(h); return e.runWebGLProgram(p, [o, r], "float32") } const EA = { kernelName: ru, backendName: "webgl", kernelFunc: LA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function DA(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { inputShape: i, strides: a, pad: c, dataFormat: l, dimRoundingMode: u } = s, d = es(l), h = ye(i, r.shape, a, 1, c, u, !1, d), p = new RA(h); return e.runWebGLProgram(p, [o, r], "float32") } const WA = { kernelName: ka, backendName: "webgl", kernelFunc: DA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function MA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dilations: c } = s, l = xs(o.shape, r.shape, i, c, a), u = new vA(l); return e.runWebGLProgram(u, [o, r], "float32") } const FA = { kernelName: Ta, backendName: "webgl", kernelFunc: MA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function VA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, pad: a, filterShape: c } = s, l = xs(o.shape, c, i, 1, a), u = new $A(l); return e.runWebGLProgram(u, [o, r], "float32") } const zA = { kernelName: iu, backendName: "webgl", kernelFunc: VA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function XA(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { pad: i, strides: a, inputShape: c } = s, l = xs(c, r.shape, a, 1, i), u = new GA(l); return e.runWebGLProgram(u, [o, r], "float32") } const AA = { kernelName: au, backendName: "webgl", kernelFunc: XA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const OA = hr + `
  return cos(x);
`, PA = Tt({ opSnippet: OA }), KA = { kernelName: $r, backendName: "webgl", kernelFunc: PA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const ZA = Tt({
        opSnippet: `
  float e2x = exp(-x);
  return (e2x + 1.0 / e2x) / 2.0;
`}), BA = { kernelName: Gr, backendName: "webgl", kernelFunc: ZA };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class HA {
        constructor(t, e, s, o, r) {
            this.variableNames = ["Image", "Boxes", "BoxInd"], this.outputShape = []; const [i, a, c, l] = t, [u] = e, [d, h] = s; this.outputShape = [u, d, h, l]; const p = o === "bilinear" ? 1 : 0, [f, m] = [`${a - 1}.0`, `${c - 1}.0`], [g, b, x] = d > 1 ? [`${(a - 1) / (d - 1)}`, "(y2-y1) * height_ratio", `y1*${f} + float(y)*(height_scale)`] : ["0.0", "0.0", `0.5 * (y1+y2) * ${f}`], [I, y, C] = h > 1 ? [`${(c - 1) / (h - 1)}`, "(x2-x1) * width_ratio", `x1*${m} + float(x)*(width_scale)`] : ["0.0", "0.0", `0.5 * (x1+x2) * ${m}`]; this.userCode = `
      const float height_ratio = float(${g});
      const float width_ratio = float(${I});
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int y = coords[1];
        int x = coords[2];
        int d = coords[3];

        // get box vals
        float y1 = getBoxes(b,0);
        float x1 = getBoxes(b,1);
        float y2 = getBoxes(b,2);
        float x2 = getBoxes(b,3);

        // get image in batch index
        int bInd = round(getBoxInd(b));
        if(bInd < 0 || bInd >= ${i}) {
          return;
        }

        float height_scale = ${b};
        float width_scale = ${y};

        float in_y = ${x};
        if( in_y < 0.0 || in_y > ${f} ) {
          setOutput(float(${r}));
          return;
        }
        float in_x = ${C};
        if( in_x < 0.0 || in_x > ${m} ) {
          setOutput(float(${r}));
          return;
        }

        vec2 sourceFracIndexCR = vec2(in_x,in_y);
        if(${p} == 1) {
          // Compute the four integer indices.
          ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);
          ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));

          float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);
          float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);
          float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);
          float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);

          vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);

          float top = topLeft + (topRight - topLeft) * fracCR.x;
          float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;
          float newValue = top + (bottom - top) * fracCR.y;
          setOutput(newValue);
        } else {
          // Compute the coordinators of nearest neighbor point.
          ivec2 sourceNearestCR = ivec2(floor(
            sourceFracIndexCR + vec2(0.5,0.5)));
          float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);
          setOutput(newValue);
        }
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _A = { kernelName: lu, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { image: o, boxes: r, boxInd: i } = t, { cropSize: a, method: c, extrapolationValue: l } = s, u = new HA(o.shape, r.shape, a, c, l); return e.runWebGLProgram(u, [o, r, i], "float32") } }; var aa; (function (n) { n.Prod = "*", n.Sum = "+" })(aa || (aa = {})); class V1 {
        constructor(t, e, s, o) {
            this.op = t, this.outputShape = e, this.variableNames = ["x"], this.customUniforms = [{ name: "index", type: "float" }]; const r = this.outputShape.length, i = this.op === aa.Prod ? "1.0" : "0.0", a = s ? i : `getX(${z1(r, "coords", this.op)})`, c = this.outputShape[this.outputShape.length - 1]; let l = "", u = ""; s ? (l = o ? `end != ${c - 1}` : "end != 0", u = o ? "end + 1" : "end - 1") : (l = o ? `end + pow2 < ${c}` : "end >= pow2", u = o ? "end + pow2" : "end - pow2"), this.userCode = `
      void main() {
        ${Xt(r)} coords = getOutputCoords();
        int end = ${X1(r, "coords", this.op)};
        float val = ${a};
        int pow2 = int(pow(2.0, index));
        if (${l}) {
          int idx = ${u};
          ${X1(r, "coords", this.op)} = idx;
          val ${this.op}= getX(${z1(r, "coords", this.op)});
        }
        setOutput(val);
      }
    `}
    } function z1(n, t, e) { if (n === 1) return `${t}`; if (n === 2) return `${t}.x, ${t}.y`; if (n === 3) return `${t}.x, ${t}.y, ${t}.z`; if (n === 4) return `${t}.x, ${t}.y, ${t}.z, ${t}.w`; throw new Error(`Cumulative ${e} for rank ${n} is not yet supported`) } function X1(n, t, e) { if (n === 1) return `${t}`; if (n === 2) return `${t}.y`; if (n === 3) return `${t}.z`; if (n === 4) return `${t}.w`; throw new Error(`Cumulative ${e} for rank ${n} is not yet supported`) }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function A1(n, t, e, s, o, r) { const i = t.shape.length, a = Yt([s], i); let c = t; a != null && (c = We({ inputs: { x: t }, backend: e, attrs: { perm: a } })); const l = te(1, i)[0]; if (l !== i - 1) throw new Error(`WebGL cumprod shader expects an inner-most axis=${t.shape.length - 1} but got axis=${s}`); const u = c.shape[l]; let d = Ye({ inputs: { x: c }, backend: e }); for (let h = 0; h <= Math.ceil(Math.log2(u)) - 1; h++) { const p = new V1(n, c.shape, !1, r), f = [[h]], m = d; d = e.runWebGLProgram(p, [d], d.dtype, f), e.disposeIntermediateTensorInfo(m) } if (o) { const h = new V1(n, c.shape, o, r), p = d; d = e.runWebGLProgram(h, [d], d.dtype), e.disposeIntermediateTensorInfo(p) } if (a != null) { const h = ys(a), p = We({ inputs: { x: d }, backend: e, attrs: { perm: h } }); return e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(c), p } return d }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function UA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, exclusive: i, reverse: a } = s; return A1(aa.Prod, o, e, r, i, a) } const YA = { kernelName: cu, backendName: "webgl", kernelFunc: UA };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, exclusive: i, reverse: a } = s; return A1(aa.Sum, o, e, r, i, a) } const JA = { kernelName: Na, backendName: "webgl", kernelFunc: QA };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jA(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, weights: r } = t, { size: i, binaryOutput: a } = s; if (o.shape.length === 1) { const c = e.readSync(o.dataId), l = e.readSync(r.dataId), u = r1(c, l, r.dtype, r.shape, i); return e.makeTensorInfo([i], r.dtype, u) } else if (o.shape.length === 2) { const c = e.bufferSync(o), l = e.bufferSync(r), u = mV(c, l, i, a); return e.makeTensorInfo(u.shape, r.dtype, u.values) } throw new Error(`Error in denseBincount: input must be at most rank 2, but got rank${o.shape.length}.`) } const qA = { kernelName: uu, backendName: "webgl", kernelFunc: jA };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class tO {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.outputShape = [], this.outputShape = t, this.blockSize = e, this.dataFormat = s, this.userCode = `
    void main() {
      ivec4 coords = getOutputCoords();
      int b = coords[0];
      int h = ${this.getHeightCoordString()};
      int w = ${this.getWidthCoordString()};
      int d = ${this.getDepthCoordString()};

      int in_h = h / ${e};
      int offset_h = imod(h, ${e});
      int in_w = w / ${e};
      int offset_w = imod(w, ${e});
      int offset_d = (offset_h * ${e} + offset_w) *
        ${this.getOutputDepthSize()};
      int in_d = d + offset_d;

      float result = ${this.getInputSamplingString()};
      setOutput(result);
    }
  `} getHeightCoordString() { return this.dataFormat === "NHWC" ? "coords[1]" : "coords[2]" } getWidthCoordString() { return this.dataFormat === "NHWC" ? "coords[2]" : "coords[3]" } getDepthCoordString() { return this.dataFormat === "NHWC" ? "coords[3]" : "coords[1]" } getOutputDepthSize() { return this.dataFormat === "NHWC" ? this.outputShape[3] : this.outputShape[1] } getInputSamplingString() { return this.dataFormat === "NHWC" ? "getX(b, in_h, in_w, in_d)" : "getX(b, in_d, in_h, in_w)" }
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function eO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockSize: r, dataFormat: i } = s, a = o.shape[0], c = i === "NHWC" ? o.shape[1] : o.shape[2], l = i === "NHWC" ? o.shape[2] : o.shape[3], u = i === "NHWC" ? o.shape[3] : o.shape[1], d = c * r, h = l * r, p = u / (r * r), f = i === "NHWC" ? [a, d, h, p] : [a, p, d, h], m = new tO(f, r, i); return e.runWebGLProgram(m, [o], o.dtype) } const nO = { kernelName: du, backendName: "webgl", kernelFunc: eO };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class O1 {
        constructor(t, e = !1, s = null, o = !1, r = !1) {
            this.variableNames = ["x", "W"], this.customUniforms = [{ name: "pads", type: "ivec2" }, { name: "strides", type: "ivec2" }, { name: "dilations", type: "ivec2" }, { name: "inDims", type: "ivec2" }], this.outputShape = t.outShape, this.enableShapeUniforms = Ee(this.outputShape.length); const i = t.filterHeight, a = t.filterWidth, c = t.outChannels / t.inChannels; let l = "", u = ""; s && (o ? l = `float activation(float a) {
          float b = getPreluActivationWeightsAtOutCoords();
          ${s}
        }`: r ? l = `float activation(float a) {
          float b = getLeakyreluAlphaAtOutCoords();
          ${s}
        }`: l = `
          float activation(float x) {
            ${s}
          }
        `, u = "result = activation(result);"); const d = e ? "result += getBiasAtOutCoords();" : ""; e && this.variableNames.push("bias"), o && this.variableNames.push("preluActivationWeights"), r && this.variableNames.push("leakyreluAlpha"), this.userCode = `
      ${l}

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords.x;
        ivec2 xRCCorner = coords.yz * strides - pads;
        int d2 = coords.w;
        int d1 = d2 / ${c};
        int q = d2 - d1 * ${c};

        int xRCorner = xRCCorner.x;
        int xCCorner = xRCCorner.y;

        // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;
        // TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.
        for (int wR = 0; wR < ${i}; wR++) {
          int xR = xRCorner + wR * dilations[0];

          if (xR < 0 || xR >= inDims[0]) {
            continue;
          }

          for (int wC = 0; wC < ${a}; wC++) {
            int xC = xCCorner + wC * dilations[1];

            if (xC < 0 || xC >= inDims[1]) {
              continue;
            }

            float xVal = getX(batch, xR, xC, d1);
            float wVal = getW(wR, wC, d1, q);
            dotProd += xVal * wVal;
          }
        }

        float result = dotProd;
        ${d}
        ${u}
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class P1 {
        constructor(t, e = !1, s = null, o = !1, r = !1) {
            this.variableNames = ["x", "W"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "pads", type: "ivec2" }, { name: "strides", type: "ivec2" }, { name: "dilations", type: "ivec2" }, { name: "inDims", type: "ivec2" }], this.outputShape = t.outShape, this.enableShapeUniforms = Ee(this.outputShape.length); const i = t.outChannels / t.inChannels, a = t.padInfo.left, c = t.strideWidth, l = t.dilationWidth, u = t.filterHeight, d = t.filterWidth, h = d; let p = `
      int xR; int xC; int xCOffset;
      vec4 wTexel; vec4 previous; vec4 final;`; for (let b = 0; b < d; b++)p += `
          vec4 xTexelC${b * 2};
          int xTexelC${b * 2}Ready;
          vec4 xTexelC${b * 2 + 1};
          int xTexelC${b * 2 + 1}Ready;
          vec4 xC${b};`; p += `
    for (int r = 0; r < ${u}; r++) {
      `; for (let b = 0; b < d; b++)p += `
          xTexelC${b * 2} = vec4(0.0);
          xTexelC${b * 2}Ready = 0;
          xTexelC${b * 2 + 1} = vec4(0.0);
          xTexelC${b * 2 + 1}Ready = 0;
          xC${b} = vec4(0.0);`; p += `
        xR = xRCorner + r * dilations[0];
        if (xR >=0 && xR < inDims[0]) {
      `; for (let b = 0; b < (h + 1) / 2; b++) {
                const x = b * 2; if (p += `
          xC = xCCorner + ${x * l};
          `, c === 1) {
                    if (x < d && (a % 2 === 1 ? (p += `
                xCOffset = xC + 1;
                if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${x}Ready == 0) {
                  xTexelC${x} = getX(batch, xR, xCOffset, d1);

                  // Need to manually clear unused channels in case
                  // we're reading from recycled texture.
                  if (xCOffset + 1 >= inDims[1]) {
                    xTexelC${x}.zw = vec2(0.0);
                  }
                  xTexelC${x}Ready = 1;
                }
              `, l === 1 && x > 0 ? p += `
                xC${x} = vec4(xTexelC${x - 2}.zw, xTexelC${x}.xy);
                `: p += `
                  xCOffset = xC + 1 - 2;

                  if (xCOffset >= 0 && xCOffset < inDims[1]) {
                    previous = getX(batch, xR, xCOffset, d1);

                    // Need to manually clear unused channels in case
                    // we're reading from recycled texture.
                    if (xCOffset + 1 >= inDims[1]) {
                      previous.zw = vec2(0.0);
                    }

                    xC${x} = vec4(previous.zw, xTexelC${x}.xy);
                  } else {
                    xC${x} = vec4(0.0, 0.0, xTexelC${x}.xy);
                  }
                  `) : p += `
                if (xC >= 0 && xC < inDims[1] && xTexelC${x}Ready == 0) {
                  xTexelC${x} = getX(batch, xR, xC, d1);
                  if (xC + 1 >= inDims[1]) {
                    xTexelC${x}.zw = vec2(0.0);
                  }
                  xTexelC${x}Ready = 1;
                }

                xC${x} = xTexelC${x};
                `, x + 1 < d)) {
                        const I = a % 2 === 0 ? Ol(l) : l; l % 2 === 0 && a % 2 === 1 || l % 2 !== 0 && a % 2 !== 1 ? (p += `
                  xCOffset = xC + imod(pads[1], 2) + ${I};

                  if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${x + 1}Ready == 0) {
                    xTexelC${x + 1} = getX(batch, xR, xCOffset, d1);

                    // Need to manually clear unused channels in case
                    // we're reading from recycled texture.
                    if (xCOffset + 1 >= inDims[1]) {
                      xTexelC${x + 1}.zw = vec2(0.0);
                    }
                    xTexelC${x + 1}Ready = 1;
                  }
                  `, l > 1 ? p += `
                    xCOffset -= 2;
                    if (xCOffset >= 0 && xCOffset < inDims[1]) {
                     previous = getX(batch, xR, xCOffset, d1);
                     xC${x + 1} = vec4(previous.zw, xTexelC${x + 1}.xy);
                    } else {
                     xC${x + 1} = vec4(0.0, 0.0, xTexelC${x + 1}.xy);
                    }
                    `: p += `
                    xC${x + 1} = vec4(xTexelC${x}.zw, xTexelC${x + 1}.xy);
                    `) : I === 1 ? p += `
                    xC${x + 1} = xTexelC${x};
                    `: p += `
                    xCOffset = xC + ${I};

                    if (xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${x + 1}Ready == 0) {
                      xTexelC${x + 1} = getX(batch, xR, xCOffset, d1);
                      if (xCOffset + 1 >= inDims[1]) {
                        xTexelC${x + 1}.zw = vec2(0.0);
                      }
                      xTexelC${x + 1}Ready = 1;
                    }

                    xC${x + 1} = xTexelC${x + 1};
                    `}
                } else x < d && (a % 2 === 1 ? (p += `
                xCOffset = xC + 1 - strides[1];
                if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${x}Ready == 0) {
                  xTexelC${x} = getX(batch, xR, xCOffset, d1);
                  // Need to manually clear unused channels in case
                  // we're reading from recycled texture.
                  if (xCOffset + 1 >= inDims[1]) {
                    xTexelC${x}.zw = vec2(0.0);
                  }
                  xTexelC${x}Ready = 1;
                }

                if(xC + 1 >= 0 && xC + 1 < inDims[1] && xTexelC${x + 1}Ready == 0) {
                  xTexelC${x + 1} = getX(batch, xR, xC + 1, d1);
                  // Need to manually clear unused channels in case
                  // we're reading from recycled texture.
                  if (xC + 2 >= inDims[1]) {
                    xTexelC${x + 1}.zw = vec2(0.0);
                  }
                  xTexelC${x + 1}Ready = 1;
                }

                xC${x} = vec4(xTexelC${x}.zw, xTexelC${x + 1}.zw);
              `, x + 1 < d && (p += `
                  final = vec4(0.0);
                  xCOffset = xC + 1 + strides[1];
                  if(xCOffset >= 0 && xCOffset < inDims[1]) {
                    final = getX(batch, xR, xCOffset, d1);
                  }
                  xC${x + 1} = vec4(xTexelC${x + 1}.xy, final.xy);
                `)) : (p += `
                if(xC >= 0 && xC < inDims[1] && xTexelC${x}Ready == 0) {
                  xTexelC${x} = getX(batch, xR, xC, d1);
                  if (xC + 1 >= inDims[1]) {
                    xTexelC${x}.zw = vec2(0.0);
                  }
                  xTexelC${x}Ready = 1;
                }

                xCOffset = xC + strides[1];
                if(xCOffset >= 0 && xCOffset < inDims[1] && xTexelC${x + 1}Ready == 0) {
                  xTexelC${x + 1} = getX(batch, xR, xCOffset, d1);
                  if (xCOffset + 1 >= inDims[1]) {
                    xTexelC${x + 1}.zw = vec2(0.);
                  }
                  xTexelC${x + 1}Ready = 1;
                }

                xC${x} = vec4(
                  xTexelC${x}.xy, xTexelC${x + 1}.xy);
              `, x + 1 < d && (p += `
                  xC${x + 1} = vec4(xTexelC${x}.zw, xTexelC${x + 1}.zw);
                `))); x < d && (p += `
            wTexel = getW(r, ${x}, d1, q);
            dotProd += xC${x} * vec4(wTexel.xz, wTexel.xz);
          `, x + 1 < d && (p += `
              wTexel = getW(r, ${x + 1}, d1, q);
              dotProd += xC${x + 1} * vec4(wTexel.xz, wTexel.xz);
            `))
            } p += `
    }
  `, p += `
      }
    `; let f = "", m = ""; s && (o ? f = `vec4 activation(vec4 a) {
          vec4 b = getPreluActivationWeightsAtOutCoords();
          ${s}
        }`: r ? f = `vec4 activation(vec4 a) {
          vec4 b = getLeakyreluAlphaAtOutCoords();
          ${s}
        }`: f = `vec4 activation(vec4 x) {
          ${s}
        }`, m = "result = activation(result);"); const g = e ? "result += getBiasAtOutCoords();" : ""; e && this.variableNames.push("bias"), o && this.variableNames.push("preluActivationWeights"), r && this.variableNames.push("leakyreluAlpha"), this.userCode = `
      ${f}

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords.x;
        ivec2 xRCCorner = coords.yz * strides - pads;
        int d2 = coords.w;
        int d1 = d2 / ${i};
        int q = d2 - d1 * ${i};
        int xRCorner = xRCCorner.x;
        int xCCorner = xRCCorner.y;

        //intialize dotProd with a small epsilon seems to reduce GPU accuracy loss.
        vec4 dotProd = vec4(0.000000000000001);

        ${p}

        vec4 result = dotProd - vec4(0.000000000000001);
        ${g}
        ${m}
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dilations: c, dimRoundingMode: l } = s; let u = c; u == null && (u = [1, 1]), v(Te(i, u), () => `Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${i} and dilations '${u}'`); const d = ye(o.shape, r.shape, i, u, a, l, !0); let h; A().getBool("WEBGL_PACK_DEPTHWISECONV") && d.strideWidth <= 2 && d.outChannels / d.inChannels === 1 ? h = new P1(d) : h = new O1(d); const p = [[d.padInfo.top, d.padInfo.left], [d.strideHeight, d.strideWidth], [d.dilationHeight, d.dilationWidth], [d.inHeight, d.inWidth]]; return e.runWebGLProgram(h, [o, r], "float32", p) } const oO = { kernelName: Ra, backendName: "webgl", kernelFunc: sO };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class rO {
        constructor(t) {
            this.variableNames = ["x", "dy"], this.outputShape = t.filterShape; const e = t.strideHeight, s = t.strideWidth, o = t.padInfo.top, r = t.padInfo.left, i = t.outChannels / t.inChannels; this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int wR = coords.x;
        int wC = coords.y;
        int d1 = coords.z;
        int dm = coords.w;
        int d2 = d1 * ${i} + dm;

        float dotProd = 0.0;

        // TO DO: Vec4 over the batch size
        for (int b = 0; b < ${t.batchSize}; b++) {
          for (int yR = 0; yR < ${t.outHeight}; yR++) {
            int xR = wR + yR * ${e} - ${o};

            if (xR < 0 || xR >= ${t.inHeight}) {
              continue;
            }

            for (int yC = 0; yC < ${t.outWidth}; yC++) {
              int xC = wC + yC * ${s} - ${r};

              if (xC < 0 || xC >= ${t.inWidth}) {
                continue;
              }

              float dyValue = getDy(b, yR, yC, d2);
              float xValue = getX(b, xR, xC, d1);
              dotProd += (xValue * dyValue);
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    } class iO {
        constructor(t) {
            this.variableNames = ["dy", "W"], this.outputShape = t.inShape; const e = t.filterHeight, s = t.filterWidth, o = t.strideHeight, r = t.strideWidth, i = e - 1 - t.padInfo.top, a = s - 1 - t.padInfo.left, c = t.outChannels / t.inChannels; this.userCode = `
      const ivec2 pads = ivec2(${i}, ${a});

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords[0];
        int d1 = coords[3];
        ivec2 dyCorner = coords.yz - pads;
        int dyRCorner = dyCorner.x;
        int dyCCorner = dyCorner.y;

        float dotProd = 0.0;

        for (int wR = 0; wR < ${e}; wR++) {
          float dyR = float(dyRCorner + wR) / ${o}.0;

          if (dyR < 0.0 || dyR >= ${t.outHeight}.0 || fract(dyR) > 0.0) {
            continue;
          }
          int idyR = int(dyR);

          int wRPerm = ${e} - 1 - wR;

          for (int wC = 0; wC < ${s}; wC++) {
            float dyC = float(dyCCorner + wC) / ${r}.0;

            if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                fract(dyC) > 0.0) {
              continue;
            }
            int idyC = int(dyC);

            int wCPerm = ${s} - 1 - wC;

            // TO DO: Vec4 over the channelMul
            for (int dm = 0; dm < ${c}; dm++) {
              int d2 = d1 * ${c} + dm;
              float xValue = getDy(batch, idyR, idyC, d2);
              float wValue = getW(wRPerm, wCPerm, d1, dm);
              dotProd += xValue * wValue;
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, dy: r } = t, { strides: i, dilations: a, pad: c, dimRoundingMode: l, filterShape: u } = s, d = ye(o.shape, u, i, a, c, l, !0), h = new rO(d); return e.runWebGLProgram(h, [o, r], "float32") } const cO = { kernelName: hu, backendName: "webgl", kernelFunc: aO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lO(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, filter: r } = t, { strides: i, dilations: a, pad: c, dimRoundingMode: l, inputShape: u } = s, d = ye(u, r.shape, i, a, c, l, !0), h = new iO(d); return e.runWebGLProgram(h, [o, r], "float32") } const uO = { kernelName: pu, backendName: "webgl", kernelFunc: lO };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class dO {
        constructor(t) {
            this.variableNames = ["X"], this.outputShape = [t, t], this.userCode = `
      void main() {
          ivec2 coords = getOutputCoords();
          float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;
          setOutput(val);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function hO(n) { const { inputs: t, backend: e } = n, { x: s } = t, o = [...s.shape, ...s.shape], r = Z(s.shape), i = et({ inputs: { x: s }, backend: e, attrs: { shape: [r] } }), a = new dO(r), c = e.runWebGLProgram(a, [i], i.dtype), l = et({ inputs: { x: c }, backend: e, attrs: { shape: o } }); return e.disposeIntermediateTensorInfo(i), e.disposeIntermediateTensorInfo(c), l } const pO = { kernelName: hf, backendName: "webgl", kernelFunc: hO };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class fO {
        constructor(t) {
            this.variableNames = ["x", "W"], this.outputShape = t.outShape; const { inHeight: e, inWidth: s, padInfo: o, strideHeight: r, strideWidth: i, filterHeight: a, filterWidth: c, dilationHeight: l, dilationWidth: u } = t, { top: d, left: h } = o; this.userCode = `
      const ivec2 strides = ivec2(${r}, ${i});
      const ivec2 pads = ivec2(${d}, ${h});
      const float neg_infinity = -3.4e38;

      void main() {
        ivec4 coords = getOutputCoords();
        int batch = coords.x;
        int d1 = coords.w;
        ivec2 outTopLeftCorner =
            coords.yz * strides - pads;
        int hBeg = outTopLeftCorner.x;
        int wBeg = outTopLeftCorner.y;

        float curVal = neg_infinity;
        for (int h = 0; h < ${a}; h++) {
          int hIn = hBeg + h * ${l};

          if (hIn >= 0 && hIn < ${e}) {
            for (int w = 0; w < ${c}; w++) {
              int wIn = wBeg + w * ${u};

              if (wIn >= 0 && wIn < ${s}) {
                float xVal = getX(batch, hIn, wIn, d1);
                float wVal = getW(h, w, d1);

                float val = xVal + wVal;
                if (val > curVal) {
                  curVal = val;
                }
              }
            }
          }
        }

        float result = curVal;
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r } = t, { strides: i, pad: a, dilations: c } = s, l = Ii(o.shape, r.shape, i, a, "NHWC", c); let u; const d = new fO(l); u = e.runWebGLProgram(d, [o, r], "float32"); const h = et({ inputs: { x: u }, backend: e, attrs: { shape: l.outShape } }); return e.disposeIntermediateTensorInfo(u), h } const gO = { kernelName: $a, backendName: "webgl", kernelFunc: mO };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bO(n) { const { inputs: t, backend: e, attrs: s } = n, { equation: o } = s, r = t, { allDims: i, summedDims: a, idDims: c } = dh(o, r.length); ph(i.length, c, r); const { path: l, steps: u } = fh(a, c), d = u.length; let h = null, p = i.length; const f = []; for (let m = 0; m < d; ++m) { for (const g of u[m]) { const { permutationIndices: b, expandDims: x } = hh(p, c[g]); let I; mh(b) ? I = r[g] : (I = We({ inputs: { x: r[g] }, backend: e, attrs: { perm: b } }), f.push(I)); const y = I.shape.slice(); for (let C = 0; C < x.length; ++C)y.splice(x[C], 0, 1); Rt(I.shape, y) || (I = et({ inputs: { x: I }, backend: e, attrs: { shape: y } }), f.push(I)), h === null ? h = I : (h = Tp({ inputs: { a: I, b: h }, backend: e }), f.push(h)) } m < d - 1 && (l[m] >= 0 && (h = Tl({ inputs: { x: h }, backend: e, attrs: { axis: l[m] - (i.length - p), keepDims: !1 } }), f.push(h)), p--) } for (const m of f) m !== h && e.disposeIntermediateTensorInfo(m); return h } const xO = { kernelName: pf, backendName: "webgl", kernelFunc: bO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const yO = Tt({
        opSnippet: "return (x >= 0.0) ? x : (exp(x) - 1.0);", packedOpSnippet: `
  vec4 result;

  result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
  result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
  result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
  result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);

  return result;
`}), IO = { kernelName: Er, backendName: "webgl", kernelFunc: yO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const CO = "return (b >= 1.0) ? a : a * (b + 1.0);", wO = `
  vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));
  return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));
`, vO = { kernelName: gu, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e } = n, { dy: s, y: o } = t, r = A().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new na(wO, s.shape, o.shape) : new dr(CO, s.shape, o.shape); return e.runWebGLProgram(r, [s, o], s.dtype) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const SO = we({
            opSnippet: "return float(a == b);", packedOpSnippet: `
  return vec4(equal(a, b));
`, dtype: "bool", cpuKernelImpl: yV
        }), kO = { kernelName: Ga, backendName: "webgl", kernelFunc: SO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const TO = `
  // Error function is calculated approximately with elementary function.
  // See "Handbook of Mathematical Functions with Formulas,
  // Graphs, and Mathematical Tables", Abramowitz and Stegun.
  float p = ${sh};
  float a1 = ${oh};
  float a2 = ${rh};
  float a3 = ${ih};
  float a4 = ${ah};
  float a5 = ${ch};

  float sign = sign(x);
  x = abs(x);
  float t = 1.0 / (1.0 + p * x);
  return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));
`, NO = Tt({ opSnippet: TO }), RO = { kernelName: Dr, backendName: "webgl", kernelFunc: NO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const $O = hr + `
  return exp(x);
`, K1 = Tt({
            opSnippet: $O, packedOpSnippet: `
  vec4 result = exp(x);
  bvec4 isNaN = isnan(x);
  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`, cpuKernelImpl: IV, dtype: "float32"
        }), GO = { kernelName: Wr, backendName: "webgl", kernelFunc: K1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Gp(n) { const { inputs: t, attrs: e, backend: s } = n, { dim: o } = e, { input: r } = t, i = r.shape.length, a = r.shape.slice(); let c = o; return o < 0 && (v(-(i + 1) <= o, () => `Axis must be in the interval [${-(i + 1)}, ${i}]`), c = i + o + 1), a.splice(c, 0, 1), et({ inputs: { x: r }, backend: s, attrs: { shape: a } }) } const LO = { kernelName: La, backendName: "webgl", kernelFunc: Gp };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Z1 = "return exp(x) - 1.0;", EO = Tt({ opSnippet: Z1, packedOpSnippet: Z1, cpuKernelImpl: CV }), DO = { kernelName: Mr, backendName: "webgl", kernelFunc: EO };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class B1 {
        constructor(t, e, s) {
            this.variableNames = ["real", "imag"]; const o = e[1]; this.outputShape = e; const r = s ? `2.0 * ${Math.PI}` : `-2.0 * ${Math.PI}`, i = s ? `${o}.0` : "1.0"; let a; if (t === "real") a = "return real * expR - imag * expI;"; else if (t === "imag") a = "return real * expI + imag * expR;"; else throw new Error(`FFT component must be either "real" or "imag", got ${t}.`); this.userCode = `
      const float exponentMultiplier = ${r};

      float unaryOpComplex(float real, float expR, float imag, float expI) {
        ${a}
      }

      float mulMatDFT(int batch, int index) {
        float indexRatio = float(index) / float(${o});
        float exponentMultiplierTimesIndexRatio =
            exponentMultiplier * indexRatio;

        float result = 0.0;

        for (int i = 0; i < ${o}; i++) {
          // x = (-2|2 * PI / N) * index * i;
          float x = exponentMultiplierTimesIndexRatio * float(i);
          float expR = cos(x);
          float expI = sin(x);
          float real = getReal(batch, i);
          float imag = getImag(batch, i);

          result +=
              unaryOpComplex(real, expR, imag, expI) / ${i};
        }

        return result;
      }

      void main() {
        ivec2 coords = getOutputCoords();
        setOutput(mulMatDFT(coords[0], coords[1]));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function H1(n, t, e) { const s = e.texData.get(n.dataId), o = Z(n.shape), r = n.shape[n.shape.length - 1], i = o / r, a = et({ inputs: { x: n }, backend: e, attrs: { shape: [i, r] } }), c = a.shape, l = new B1("real", c, t), u = new B1("imag", c, t), d = [{ dataId: s.complexTensorInfos.real.dataId, dtype: s.complexTensorInfos.real.dtype, shape: c }, { dataId: s.complexTensorInfos.imag.dataId, dtype: s.complexTensorInfos.imag.dtype, shape: c }], h = e.runWebGLProgram(l, d, "float32"), p = e.runWebGLProgram(u, d, "float32"), f = Ws({ inputs: { real: h, imag: p }, backend: e }); e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p); const m = et({ inputs: { x: f }, backend: e, attrs: { shape: n.shape } }); return e.disposeIntermediateTensorInfo(a), e.disposeIntermediateTensorInfo(f), m }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function WO(n) { const { inputs: t, backend: e } = n, { input: s } = t; return H1(s, !1, e) } const MO = { kernelName: bu, backendName: "webgl", kernelFunc: WO };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class FO {
        constructor(t, e) {
            this.outputShape = [], this.customUniforms = [{ name: "value", type: "float" }], this.variableNames = ["x"], this.outputShape = t, this.userCode = `
      void main() {
        // Input can be obtained from uniform value.
        setOutput(value);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function ca(n) { const { backend: t, attrs: e } = n, { shape: s, value: o } = e; let { dtype: r } = e; if (r = r || xr(o), r === "string") { const i = ne(r, Z(s)); return i.fill(o), t.makeTensorInfo(s, r, i) } else { const i = new FO(s, o), a = [[o]]; return t.runWebGLProgram(i, [], r, a) } } const VO = { kernelName: xu, backendName: "webgl", kernelFunc: ca };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class zO {
        constructor(t) {
            this.variableNames = ["Image"], this.outputShape = []; const e = t[2]; this.outputShape = t, this.userCode = `
        void main() {
          ivec4 coords = getOutputCoords();
          int x = coords[2];

          int coordX = ${e} - x - 1;
          float outputValue;
          if(coordX >= 0 && coordX < ${e}) {
            outputValue = getImage(coords[0], coords[1], coordX, coords[3]);
          } else {
            outputValue = getImage(coords[0], coords[1], coords[2], coords[3]);
          }
          setOutput(outputValue);
        }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const XO = { kernelName: yu, backendName: "webgl", kernelFunc: ({ inputs: n, backend: t }) => { const { image: e } = n, s = t, o = new zO(e.shape); return s.runWebGLProgram(o, [e], e.dtype) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const _1 = "return floor(x);", AO = Tt({ opSnippet: _1, packedOpSnippet: _1, cpuKernelImpl: wV }), OO = { kernelName: Fr, backendName: "webgl", kernelFunc: AO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const PO = we({
        opSnippet: `
  float s = sign(a) * sign(b);
  int ia = round(a);
  int ib = round(b);
  if (ib != 0) {
    // Windows (D3D) wants guaranteed non-zero int division at compile-time.
    return float(idiv(ia, ib, s));
  } else {
    return NAN;
  }
`, packedOpSnippet: `
  ivec4 ia = round(a);
  ivec4 ib = round(b);
  bvec4 cond = notEqual(ib, ivec4(0));
  ivec4 result = ivec4(0);
  vec4 s = sign(a) * sign(b);

  // Windows (D3D) wants guaranteed non-zero int division at compile-time.
  if (cond[0]) {
    result[0] = idiv(ia[0], ib[0], s[0]);
  }
  if (cond[1]) {
    result[1] = idiv(ia[1], ib[1], s[1]);
  }
  if (cond[2]) {
    result[2] = idiv(ia[2], ib[2], s[2]);
  }
  if (cond[3]) {
    result[3] = idiv(ia[3], ib[3], s[3]);
  }
  return vec4(result);
`, dtype: "int32"
    }), KO = { kernelName: Vr, backendName: "webgl", kernelFunc: PO };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class ZO {
        constructor(t) {
            this.variableNames = ["A"]; const e = Le(), [s, o] = t; this.outputShape = t, this.userCode = `
      void main() {
        ivec3 coords = getOutputCoords();
        int texR = coords[0];
        int texC = coords[1];
        int depth = coords[2];
        vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${o}.0, ${s}.0);

        vec4 values = ${e.texture2D}(A, uv);
        float value;
        if (depth == 0) {
          value = values.r;
        } else if (depth == 1) {
          value = values.g;
        } else if (depth == 2) {
          value = values.b;
        } else if (depth == 3) {
          value = values.a;
        }

        setOutput(floor(value * 255.0 + 0.5));
      }
    `}
    }/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class BO {
        constructor(t) {
            this.variableNames = ["A"], this.packedInputs = !1, this.packedOutput = !0; const e = Le(), [s, o] = t; this.outputShape = t, this.userCode = `
      void main() {
        ivec3 coords = getOutputCoords();
        int texR = coords[0];
        int texC = coords[1];
        int depth = coords[2];

        vec4 result = vec4(0.);

        for(int row=0; row<=1; row++) {
          for(int col=0; col<=1; col++) {
            texC = coords[1] + row;
            depth = coords[2] + col;

            vec2 uv = (vec2(texC, texR) + halfCR) /
                       vec2(${o}.0, ${s}.0);
            vec4 values = ${e.texture2D}(A, uv);
            float value;
            if (depth == 0) {
              value = values.r;
            } else if (depth == 1) {
              value = values.g;
            } else if (depth == 2) {
              value = values.b;
            } else if (depth == 3) {
              value = values.a;
            }

            result[row * 2 + col] = floor(value * 255.0 + 0.5);
          }
        }

        ${e.output} = result;
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const HO = { kernelName: Vu, backendName: "webgl", kernelFunc: _O }; let fr, Lp = A().getBool("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU"); function _O(n) { const { inputs: t, backend: e, attrs: s } = n; let { pixels: o } = t; const { numChannels: r } = s, i = typeof HTMLVideoElement < "u" && o instanceof HTMLVideoElement, a = typeof HTMLImageElement < "u" && o instanceof HTMLImageElement, [c, l] = i ? [o.videoWidth, o.videoHeight] : [o.width, o.height], u = [l, c], d = [l, c, r]; if (a || i) { const m = A().getBool("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU"); (fr == null || m !== Lp) && (Lp = m, fr = document.createElement("canvas").getContext("2d", { willReadFrequently: Lp })), fr.canvas.width = c, fr.canvas.height = l, fr.drawImage(o, 0, 0, c, l), o = fr.canvas } const h = e.makeTensorInfo(u, "int32"); e.texData.get(h.dataId).usage = an.PIXELS, e.gpgpu.uploadPixelDataToTexture(e.getTexture(h.dataId), o); const p = A().getBool("WEBGL_PACK") ? new BO(d) : new ZO(d), f = e.runWebGLProgram(p, [h], "int32"); return e.disposeData(h.dataId), f }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function UO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r, bias: i, preluActivationWeights: a } = t, { strides: c, pad: l, dataFormat: u, dilations: d, dimRoundingMode: h, activation: p, leakyreluAlpha: f } = s, m = es(u), g = ye(o.shape, r.shape, c, d, l, h, !1, m); let b; const x = [], I = i != null, y = a != null, C = p === "leakyrelu", w = () => { const S = [o, r], T = (R, G) => { if (G === "NCHW" && R.shape.length === 1 && R.shape[0] !== 1) { const F = et({ inputs: { x: R }, backend: e, attrs: { shape: [R.shape[0], 1, 1] } }); return x.push(F), F } return R }; if (I && S.push(T(i, u)), y && S.push(T(a, u)), C) { const R = e.makeTensorInfo([], "float32", ps(f, "float32")); S.push(R), x.push(R) } return S }; if (g.filterHeight === 1 && g.filterWidth === 1 && g.dilationHeight === 1 && g.dilationWidth === 1 && g.strideHeight === 1 && g.strideWidth === 1 && (g.padInfo.type === "SAME" || g.padInfo.type === "VALID")) b = M1({ x: o, filter: r, convInfo: g, backend: e, bias: i, activation: p, preluActivationWeights: a, leakyreluAlpha: f }); else if (g.strideWidth <= 2 && m === "channelsLast" && A().getBool("WEBGL_EXP_CONV")) { const S = p ? sa(p, !0) : null, T = new W1(g, I, S, y, C), R = [[g.padInfo.top, g.padInfo.left], [g.strideHeight, g.strideWidth], [g.dilationHeight, g.dilationWidth], [g.inHeight, g.inWidth]], G = w(); b = e.runWebGLProgram(T, G, "float32", R) } else if (A().getBool("WEBGL_CONV_IM2COL")) b = F1({ x: o, filter: r, convInfo: g, backend: e, bias: i, activation: p, preluActivationWeights: a, leakyreluAlpha: f }); else { const S = p ? sa(p, !1) : null, T = new D1(g, I, S, y, C), R = w(); b = e.runWebGLProgram(T, R, "float32") } const k = et({ inputs: { x: b }, backend: e, attrs: { shape: g.outShape } }); return x.push(b), x.forEach(S => e.disposeIntermediateTensorInfo(S)), k } const YO = { kernelName: gc, backendName: "webgl", kernelFunc: UO };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QO(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, filter: r, bias: i, preluActivationWeights: a } = t, { strides: c, pad: l, dilations: u, dimRoundingMode: d, activation: h, leakyreluAlpha: p } = s, f = []; let m = u; m == null && (m = [1, 1]), v(Te(c, m), () => `Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides ${c} and dilations '${m}'`); const g = ye(o.shape, r.shape, c, m, l, d, !0), b = A().getBool("WEBGL_PACK_DEPTHWISECONV") && g.strideWidth <= 2 && g.outChannels / g.inChannels === 1, x = h ? sa(h, b) : null, I = [o, r], y = i != null, C = a != null, w = h === "leakyrelu"; if (y && I.push(i), C && I.push(a), w) { const R = e.makeTensorInfo([], "float32", ps(p, "float32")); I.push(R), f.push(R) } let k; b ? k = new P1(g, y, x, C, w) : k = new O1(g, y, x, C, w); const S = [[g.padInfo.top, g.padInfo.left], [g.strideHeight, g.strideWidth], [g.dilationHeight, g.dilationWidth], [g.inHeight, g.inWidth]], T = e.runWebGLProgram(k, I, "float32", S); return f.forEach(R => e.disposeIntermediateTensorInfo(R)), T } const JO = { kernelName: Lf, backendName: "webgl", kernelFunc: QO }; class jO {
        constructor(t, e, s, o) {
            this.sliceDim = t, this.strides = e, this.paramsShape = o, this.variableNames = ["x", "indices"], this.outputShape = s; const r = Xt(s.length); let i = `
    int index;`; for (let a = 0; a < this.sliceDim; a++)i += `
          index = round(getIndices(coords[0], ${a}));
          out_of_bounds = out_of_bounds || index < 0;
          out_of_bounds = out_of_bounds || index >= ${this.paramsShape[a]};
          flattenIndex += index * ${this.strides[a]};`; this.userCode = `
         void main() {
          ${r} coords = getOutputCoords();
          int flattenIndex = 0;
          bool out_of_bounds = false;

          ${i}

          setOutput(out_of_bounds ? 0.0 : getX(flattenIndex, coords[1]));
        }
      `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qO(n) { const { inputs: t, backend: e } = n, { params: s, indices: o } = t, r = o.shape, i = r[r.length - 1], a = Z(s.shape), [c, l, u, d] = Bd(s, o), h = et({ inputs: { x: o }, backend: e, attrs: { shape: [l, i] } }), p = et({ inputs: { x: s }, backend: e, attrs: { shape: [Z(s.shape) / u, u] } }); if (e.shouldExecuteOnCPU([s, o]) || s.dtype === "string") { const b = e.readSync(o.dataId), x = e.bufferSync(s), I = vV(b, x, s.dtype, l, i, u, d, s.shape, a); return e.makeTensorInfo(c, s.dtype, I.values) } const f = new jO(i, d, [l, u], s.shape), m = e.runWebGLProgram(f, [p, h], p.dtype), g = et({ inputs: { x: m }, backend: e, attrs: { shape: c } }); return e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(m), g } const tP = { kernelName: ff, backendName: "webgl", kernelFunc: qO };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class eP {
        constructor(t, e) {
            this.variableNames = ["A", "indices"], this.outputShape = e, this.rank = e.length; const s = Xt(this.rank), o = nP(t); this.userCode = `
      void main() {
        ${s} resRC = getOutputCoords();
        int index = int(getIndices(resRC.x, resRC.z));
        float inBounds = (index >= 0) && (index < ${t[2]}) ? 1.0 : 0.0;
        setOutput(inBounds * getA(${o}));
      }
    `}
    } function nP(n, t) { const e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], s = []; for (let o = 0; o < n.length; o++)o === 2 ? s.push("index") : s.push(`${e[o]}`); return s.join() }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function U1(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, indices: r } = t, { axis: i, batchDims: a } = s, c = It(i, o.shape)[0]; if (A().get("DEBUG")) { const x = e.readSync(r.dataId), I = o.shape[c]; for (let y = 0; y < x.length; ++y) { const C = x[y]; v(C <= I - 1 && C >= 0, () => `GatherV2: the index value ${C} is not in [0, ${I - 1}]`) } } const l = xh(o, r, c, a), u = Z(r.shape), d = [], h = et({ inputs: { x: o }, backend: e, attrs: { shape: [l.batchSize, l.outerSize, l.dimSize, l.sliceSize] } }), p = et({ inputs: { x: r }, backend: e, attrs: { shape: [l.batchSize, u / l.batchSize] } }); d.push(h), d.push(p); const f = [l.batchSize, l.outerSize, u / l.batchSize, l.sliceSize]; if (e.shouldExecuteOnCPU([o, r]) || o.dtype === "string") { const x = e.bufferSync(p), I = e.bufferSync(h), y = SV(I, x, f); return d.forEach(C => e.disposeIntermediateTensorInfo(C)), e.makeTensorInfo(l.outputShape, y.dtype, y.values) } const m = new eP(h.shape, f), g = e.runWebGLProgram(m, [h, p], h.dtype); d.push(g); const b = et({ inputs: { x: g }, backend: e, attrs: { shape: l.outputShape } }); return d.forEach(x => e.disposeIntermediateTensorInfo(x)), b } const sP = { kernelName: Da, backendName: "webgl", kernelFunc: U1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oP = we({
        opSnippet: "return float(a > b);", packedOpSnippet: `
  return vec4(greaterThan(a, b));
`, cpuKernelImpl: kV, dtype: "bool"
    }), rP = { kernelName: Wa, backendName: "webgl", kernelFunc: oP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iP = we({
        opSnippet: "return float(a >= b);", packedOpSnippet: `
  return vec4(greaterThanEqual(a, b));
`, dtype: "bool", cpuKernelImpl: TV
    }), aP = { kernelName: zr, backendName: "webgl", kernelFunc: iP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function cP(n) { const { inputs: t, backend: e } = n, { input: s } = t; return H1(s, !0, e) } const lP = { kernelName: Iu, backendName: "webgl", kernelFunc: cP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uP = Tt({ opSnippet: "return float(!isnan(x) && !isinf(x));", dtype: "bool" }), dP = { kernelName: Ar, backendName: "webgl", kernelFunc: uP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const hP = Tt({ opSnippet: "return float(isinf(x));", dtype: "bool" }), pP = { kernelName: Or, backendName: "webgl", kernelFunc: hP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const fP = Tt({ opSnippet: "return float(isnan(x));", dtype: "bool" }), mP = { kernelName: Pr, backendName: "webgl", kernelFunc: fP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const gP = we({
        opSnippet: "return float(a < b);", packedOpSnippet: `
  return vec4(lessThan(a, b));
`, cpuKernelImpl: NV, dtype: "bool"
    }), bP = { kernelName: Fa, backendName: "webgl", kernelFunc: gP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const xP = we({
        opSnippet: "return float(a <= b);", packedOpSnippet: `
  return vec4(lessThanEqual(a, b));
`, cpuKernelImpl: RV, dtype: "bool"
    }), yP = { kernelName: Va, backendName: "webgl", kernelFunc: xP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function IP(n) { const { backend: t, attrs: e } = n, { start: s, stop: o, num: r } = e, i = $V(s, o, r); return t.makeTensorInfo([i.length], "float32", i) } const CP = { kernelName: mf, backendName: "webgl", kernelFunc: IP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const wP = hr + `
  return x < 0.0 ? 0./0. : log(x);
`, vP = Tt({
        opSnippet: wP, packedOpSnippet: `
  vec4 result = log(x);
  bvec4 isNaN = isnan(x);
  result.r = isNaN.r ? x.r : (x.r < 0.0 ? 0./0. : result.r);
  result.g = isNaN.g ? x.g : (x.g < 0.0 ? 0./0. : result.g);
  result.b = isNaN.b ? x.b : (x.b < 0.0 ? 0./0. : result.b);
  result.a = isNaN.a ? x.a : (x.a < 0.0 ? 0./0. : result.a);
  return result;
`, cpuKernelImpl: GV
    }), SP = { kernelName: Kr, backendName: "webgl", kernelFunc: vP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const kP = hr + `
  return log(1.0 + x);
`, TP = Tt({ opSnippet: kP }), NP = { kernelName: Zr, backendName: "webgl", kernelFunc: TP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const RP = we({
        opSnippet: "return float(a >= 1.0 && b >= 1.0);", packedOpSnippet: `
  return vec4(
    vec4(greaterThanEqual(a, vec4(1.0))) *
    vec4(greaterThanEqual(b, vec4(1.0))));
`, dtype: "bool"
    }), $P = { kernelName: za, backendName: "webgl", kernelFunc: RP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const GP = Tt({ opSnippet: "return float(!(x >= 1.0));" }), LP = { kernelName: Xa, backendName: "webgl", kernelFunc: GP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const EP = we({
        opSnippet: "return float(a >= 1.0 || b >= 1.0);", packedOpSnippet: `
  return min(
    vec4(greaterThanEqual(a, vec4(1.0))) +
    vec4(greaterThanEqual(b, vec4(1.0))),
    vec4(1.0));
`, dtype: "bool"
    }), DP = { kernelName: Aa, backendName: "webgl", kernelFunc: EP };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class WP {
        constructor(t, e, s, o, r) {
            this.variableNames = ["x"], this.outputShape = []; const i = e, a = t[3] - 1; this.outputShape = t; let c; const l = `float(${s}) + float(${o}) * sum`; r === .5 ? c = `inversesqrt(${l})` : r === 1 ? c = `1.0/(${l})` : c = `exp(log(${l}) * float(-${r}));`, this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int r = coords[1];
        int c = coords[2];
        int d = coords[3];
        float x = getX(b, r, c, d);
        float sum = 0.0;
        for (int j = -${i}; j <= ${i}; j++) {
          int idx = d + j;
          if (idx >= 0 && idx <=  ${a}) {
            float z = getX(b, r, c, idx);
            sum += z * z;
          }
        }
        float val = x * ${c};
        setOutput(val);
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class MP {
        constructor(t, e, s, o, r) {
            this.variableNames = ["x"], this.outputShape = [], this.packedInputs = !0, this.packedOutput = !0; const i = e, a = t[3] - 1; this.outputShape = t; let c; const l = `float(${s}) + float(${o}) * sum`; r === .5 ? c = `inversesqrt(${l})` : r === 1 ? c = `1.0/(${l})` : c = `exp(log(${l}) * float(-${r}));`, this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords.x;
        int r = coords.y;
        int c = coords.z;
        int d = coords.w;

        bool hasNextCol = d < ${this.outputShape[3]};
        bool hasNextRow = c < ${this.outputShape[2]};

        vec4 sum = vec4(0.);
        vec4 xFragAtOutputCoords = getX(b, r, c, d);

        vec4 xAtOutputCoords = vec4(
          getChannel(xFragAtOutputCoords, vec2(c, d)),
          hasNextCol ?
            getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,
          hasNextRow ?
            getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,
          (hasNextRow && hasNextCol) ?
            getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0
        );

        int firstChannel = d - ${i};
        vec2 cache = vec2(0.);
        if(firstChannel >= 0){
          vec4 firstChannelFrag = getX(b, r, c, firstChannel);
          cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));
            if(hasNextRow){
              cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));
            }
        }

        ivec2 depth = ivec2(d, d + 1);
        for (int j = - ${i}; j <= ${i}; j++) {
          ivec2 idx = depth + j;
          bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));
          bvec2 belowUpperBound = lessThanEqual(idx, ivec2(${a}));

          bool depthInRange = aboveLowerBound.x && belowUpperBound.x;
          bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;

          if(depthInRange || depthPlusOneInRange){
            vec4 z = vec4(0.);
            vec4 xFragAtCurrentDepth;
            z.xz = cache.xy;
            if(depthPlusOneInRange && hasNextCol){
              xFragAtCurrentDepth = idx.y != d ?
                getX(b, r, c, idx.y) : xFragAtOutputCoords;
              z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));
              if(hasNextRow){
                z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));
              }
            }
            cache.xy = z.yw;
            sum += z * z;
          }
        }
        vec4 result = xAtOutputCoords * ${c};
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const FP = { kernelName: Oa, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { depthRadius: r, bias: i, alpha: a, beta: c } = s, l = A().getBool("WEBGL_PACK_NORMALIZATION") ? new MP(o.shape, r, i, a, c) : new WP(o.shape, r, i, a, c); return e.runWebGLProgram(l, [o], o.dtype) } };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class VP {
        constructor(t, e, s, o, r) {
            this.variableNames = ["inputImage", "outputImage", "dy"], this.outputShape = [], this.outputShape = t, this.depth = t[3], this.depthRadius = e, this.bias = s, this.alpha = o, this.beta = r, this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int r = coords[1];
        int c = coords[2];

        float result = 0.0;
        for (int d = 0; d < ${this.depth}; ++d) {
          int depthBegin = int(max(0.0, float(d - ${e})));
          int depthEnd = int(min(float(${this.depth}),
              float(d + ${e} + 1)));

          const int MIN_DEPTH_BEGIN = 0;
          const int MAX_DEPTH_END = ${this.depth};

          float norm = 0.0;
          for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {
            if (k < depthBegin){
              continue;
            }
            else if (k >= depthBegin && k < depthEnd) {
              norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);
            }
            else {
              break;
            }
          }

          norm = float(${o}) * norm + float(${s});

          for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){
            if (k < depthBegin){
              continue;
            }
            else if (k >= depthBegin && k < depthEnd){
              float dyi = -2.0 * float(${o})
                * float(${r})
                * getInputImage(b, r, c, k) * getOutputImage(b, r, c, d)
                / norm;
              if (k == d) {
                dyi += pow(norm, -1.0 * ${r});
              }
              if (k == coords[3]) {
                dyi *= getDy(b, r, c, d);
                result += dyi;
              }
            }
            else {
              break;
            }
          }
      }
      setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zP = { kernelName: wu, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { x: o, y: r, dy: i } = t, { depthRadius: a, bias: c, alpha: l, beta: u } = s, d = new VP(o.shape, a, c, l, u); return e.runWebGLProgram(d, [o, r, i], o.dtype) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function XP(n, t, e, s) { const o = Z(t), i = Z(n.shape) / o, a = et({ inputs: { x: n }, attrs: { shape: [i, o] }, backend: s }), c = wo(a, n.dtype, "max", s), l = et({ inputs: { x: c }, attrs: { shape: e }, backend: s }); return s.disposeIntermediateTensorInfo(a), s.disposeIntermediateTensorInfo(c), l }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function Y1(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { reductionIndices: r, keepDims: i } = s, a = o.shape.length, c = It(r, o.shape); let l = c; const u = Yt(l, a), d = u != null, h = e.shouldExecuteOnCPU([o]); let p = o; if (d) { if (h) { const I = e.texData.get(p.dataId).values, y = new Array(a); for (let k = 0; k < y.length; k++)y[k] = o.shape[u[k]]; const C = Sp(I, o.shape, o.dtype, u, y); p = e.makeTensorInfo(y, o.dtype); const w = e.texData.get(p.dataId); w.values = C } else p = kl(o, u, e); l = te(l.length, a) } Ie("max", l, a); const [f, m] = fe(p.shape, l); let g = f; i && (g = oe(f, c)); let b; if (h) { const I = e.texData.get(p.dataId).values, y = LV(I, Z(m), g, o.dtype); b = e.makeTensorInfo(g, o.dtype); const C = e.texData.get(b.dataId); C.values = y } else b = XP(p, m, g, e); return d && e.disposeIntermediateTensorInfo(p), b } const AP = { kernelName: Pa, backendName: "webgl", kernelFunc: Y1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const OP = kp + `
  return max(a, b);
`, PP = `
  vec4 result = vec4(max(a, b));
  bvec4 isNaNA = isnan(a);
  bvec4 isNaNB = isnan(b);
  bvec4 isNaN = bvec4(isNaNA.x || isNaNB.x, isNaNA.y || isNaNB.y, isNaNA.z || isNaNB.z, isNaNA.w || isNaNB.w);
  `+ ea + `
  return result;
`, KP = we({ opSnippet: OP, packedOpSnippet: PP, cpuKernelImpl: EV }), ZP = { kernelName: Br, backendName: "webgl", kernelFunc: KP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function BP(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t; qi(o, "maxPool"); const { filterSize: r, strides: i, pad: a, dimRoundingMode: c } = s, l = 1; v(Te(i, l), () => `Error in maxPool: Either strides or dilations must be 1. Got strides ${i} and dilations '${l}'`); const u = hn(o.shape, r, i, l, a, c); if (u.filterWidth === 1 && u.filterHeight === 1 && Rt(u.inShape, u.outShape)) return Ye({ inputs: { x: o }, backend: e }); const d = new oa(u, "max", !1); return e.runWebGLProgram(d, [o], o.dtype) } const HP = { kernelName: Ka, backendName: "webgl", kernelFunc: BP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function _P(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { filterSize: r, strides: i, pad: a, dataFormat: c, dimRoundingMode: l } = s, u = [1, 1, 1], d = ts(o.shape, r, i, u, a, l, c), h = new Np(d, "max", !1); return e.runWebGLProgram(h, [o], o.dtype) } const UP = { kernelName: Za, backendName: "webgl", kernelFunc: _P };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class YP {
        constructor(t) {
            this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape; const e = t.strideHeight, s = t.strideWidth, o = t.dilationHeight, r = t.effectiveFilterHeight, i = t.effectiveFilterWidth, a = r - 1 - t.padInfo.top, c = i - 1 - t.padInfo.left, l = r * i - 1; this.userCode = `
      const ivec2 pads = ivec2(${a}, ${c});

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];

        ivec2 dyRCCorner = coords.yz - pads;
        int dyRCorner = dyRCCorner.x;
        int dyCCorner = dyRCCorner.y;

        // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;
        for (int wR = 0; wR < ${r};
          wR += ${o}) {
          float dyR = float(dyRCorner + wR) / ${e}.0;

          if (dyR < 0.0 || dyR >= ${t.outHeight}.0 || fract(dyR) > 0.0) {
            continue;
          }
          int idyR = int(dyR);

          for (int wC = 0; wC < ${i}; wC++) {
            float dyC = float(dyCCorner + wC) / ${s}.0;

            if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                fract(dyC) > 0.0) {
              continue;
            }
            int idyC = int(dyC);

            float dyValue = getDy(b, idyR, idyC, d);
            int maxPosValue = ${l} - int(getMaxPos(b, idyR, idyC, d));

            // Get the current value, check it against the value from the
            // position matrix.
            int curPosValue = wR * ${i} + wC;
            float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);

            dotProd += dyValue * mask;
          }
        }
        setOutput(dotProd);
      }
    `}
    } class QP {
        constructor(t) {
            this.variableNames = ["dy", "maxPos"], this.outputShape = t.inShape; const e = t.strideDepth, s = t.strideHeight, o = t.strideWidth, r = t.dilationDepth, i = t.dilationHeight, a = t.dilationWidth, c = t.effectiveFilterDepth, l = t.effectiveFilterHeight, u = t.effectiveFilterWidth, d = c - 1 - t.padInfo.front, h = l - 1 - t.padInfo.top, p = u - 1 - t.padInfo.left, f = c * l * u - 1; this.userCode = `
      const ivec3 pads = ivec3(${d}, ${h}, ${p});

      void main() {
        ivec5 coords = getOutputCoords();
        int batch = coords.x;
        int ch = coords.u;

        ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;
        int dyDCorner = dyCorner.x;
        int dyRCorner = dyCorner.y;
        int dyCCorner = dyCorner.z;

        // Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
        // dx(xD, xR, xC, ch).
        // ? = to be determined. : = across all values in that axis.
        float dotProd = 0.0;

        for (int wD = 0; wD < ${c};
           wD += ${r}) {
          float dyD = float(dyDCorner + wD) / ${e}.0;

          if (dyD < 0.0 || dyD >= ${t.outDepth}.0 || fract(dyD) > 0.0) {
            continue;
          }
          int idyD = int(dyD);

          for (int wR = 0; wR < ${l};
              wR += ${i}) {
            float dyR = float(dyRCorner + wR) / ${s}.0;

            if (dyR < 0.0 || dyR >= ${t.outHeight}.0 ||
                fract(dyR) > 0.0) {
              continue;
            }
            int idyR = int(dyR);

            for (int wC = 0; wC < ${u};
                wC += ${a}) {
              float dyC = float(dyCCorner + wC) / ${o}.0;

              if (dyC < 0.0 || dyC >= ${t.outWidth}.0 ||
                  fract(dyC) > 0.0) {
                continue;
              }
              int idyC = int(dyC);

              float dyValue = getDy(batch, idyD, idyR, idyC, ch);
              int maxPosValue = ${f} -
                  int(getMaxPos(batch, idyD, idyR, idyC, ch));

              // Get the current value, check it against the value from the
              // position matrix.
              int curPosValue =
                  wD * ${l} * ${u} +
                  wR * ${u} + wC;
              float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);

              dotProd += dyValue * mask;
            }
          }
        }
        setOutput(dotProd);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function JP(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r } = t, i = r, { filterSize: a, strides: c, pad: l, dimRoundingMode: u } = s, d = [1, 1, 1], h = ts(i.shape, a, c, d, l, u), p = new Np(h, "max", !0), f = e.runWebGLProgram(p, [i], i.dtype), m = new QP(h), g = e.runWebGLProgram(m, [o, f], i.dtype); return e.disposeIntermediateTensorInfo(f), g } const jP = { kernelName: Su, backendName: "webgl", kernelFunc: JP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function qP(n) { const { inputs: t, backend: e, attrs: s } = n, { dy: o, input: r, output: i } = t, a = r; qi([r, i], "maxPoolGrad"); const { filterSize: c, strides: l, pad: u, dimRoundingMode: d } = s, h = hn(a.shape, c, l, 1, u, d), p = !0, f = new oa(h, "max", p), m = e.runWebGLProgram(f, [a], a.dtype), g = new YP(h), b = e.runWebGLProgram(g, [o, m], a.dtype); return e.disposeIntermediateTensorInfo(m), b } const tK = { kernelName: vu, backendName: "webgl", kernelFunc: qP };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function eK(n, t, e, s) { let o = new oa(e, "max", !1); const r = s.runWebGLProgram(o, [n], "float32"); o = new oa(e, "max", !0, !0, t); const i = s.runWebGLProgram(o, [n], "float32"); return [r, i] }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const nK = { kernelName: gf, backendName: "webgl", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { x: s } = n, { filterSize: o, strides: r, pad: i, includeBatchInIndex: a } = t, c = e; v(s.shape.length === 4, () => `Error in maxPool: input must be rank 4 but got rank ${s.shape.length}.`); const l = [1, 1]; v(Te(r, l), () => `Error in maxPool: Either strides or dilations must be 1. Got strides ${r} and dilations '${l}'`); const u = hn(s.shape, o, r, l, i), [d, h] = eK(s, a, u, c); return [d, h] } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function sK(n, t, e, s) { const o = Z(t), i = Z(n.shape) / o, a = et({ inputs: { x: n }, attrs: { shape: [i, o] }, backend: s }), c = wo(a, "float32", "mean", s), l = et({ inputs: { x: c }, attrs: { shape: e }, backend: s }); return s.disposeIntermediateTensorInfo(a), s.disposeIntermediateTensorInfo(c), l }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oK = { kernelName: Ba, backendName: "webgl", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { x: s } = n, { keepDims: o, axis: r } = t, i = e, a = s.shape.length, c = It(r, s.shape); let l = c; const u = Yt(l, a), d = u != null, h = i.shouldExecuteOnCPU([s]), p = []; let f = s; if (d) { if (h) { const y = i.texData.get(f.dataId).values, C = new Array(a); for (let S = 0; S < C.length; S++)C[S] = s.shape[u[S]]; const w = Sp(y, s.shape, s.dtype, u, C); f = i.makeTensorInfo(C, s.dtype); const k = i.texData.get(f.dataId); k.values = w } else f = kl(s, u, i); p.push(f), l = te(l.length, a) } Ie("sum", l, a); const [m, g] = fe(f.shape, l); let b = m; o && (b = oe(m, c)); const x = sK(f, g, b, i); for (const I of p) i.disposeIntermediateTensorInfo(I); return x } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function rK(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s, a = o.shape.length, c = It(r, o.shape); let l = c; const u = Yt(l, a); let d = o; u != null && (d = We({ inputs: { x: o }, backend: e, attrs: { perm: u } }), l = te(l.length, o.shape.length)), Ie("min", l, a); const [h, p] = fe(d.shape, l), f = Z(p), m = et({ inputs: { x: d }, backend: e, attrs: { shape: [-1, f] } }), g = wo(m, m.dtype, "min", e); let b; if (i) { const x = oe(h, c); b = et({ inputs: { x: g }, backend: e, attrs: { shape: x } }) } else b = et({ inputs: { x: g }, backend: e, attrs: { shape: h } }); return e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(g), u != null && e.disposeIntermediateTensorInfo(d), b } const iK = { kernelName: Ha, backendName: "webgl", kernelFunc: rK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aK = kp + `
  return min(a, b);
`, cK = `
  vec4 result = vec4(min(a, b));
  bvec4 isNaNA = isnan(a);
  bvec4 isNaNB = isnan(b);
  bvec4 isNaN = bvec4(isNaNA.x || isNaNB.x, isNaNA.y || isNaNB.y, isNaNA.z || isNaNB.z, isNaNA.w || isNaNB.w);
  `+ ea + `
  return result;
`, lK = we({ opSnippet: aK, packedOpSnippet: cK, cpuKernelImpl: DV }), uK = { kernelName: Hr, backendName: "webgl", kernelFunc: lK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class dK {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.outputShape = e.map((u, d) => u[0] + t[d] + u[1]); const o = t.length, r = Xt(o), i = e.map(u => u[0]).join(","), a = e.map((u, d) => u[0] + t[d]).join(","), c = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, o), l = s === "reflect" ? 0 : 1; if (o === 1) {
                this.userCode = `
        int start = ${i};
        int end = ${a};

        void main() {
          int outC = getOutputCoords();
          if (outC < start) {
            outC = start * 2 - outC - ${l};
          } else if(outC >= end) {
            outC = (end - 1) * 2 - outC + ${l};
          }
          setOutput(getX(outC - start));
        }
      `; return
            } this.userCode = `
      ${r} start = ${r}(${i});
      ${r} end = ${r}(${a});

      void main() {
        ${r} outC = getOutputCoords();
        for (int i = 0; i < ${o}; i++) {
          if (outC[i] < start[i]) {
            outC[i] = start[i] * 2 - outC[i] - ${l};
          } else if(outC[i] >= end[i]) {
            outC[i] = (end[i] - 1) * 2 - outC[i] + ${l};
          }
        }
        ${r} coords = outC - start;
        setOutput(getX(${c}));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class hK {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e.map((f, m) => f[0] + t[m] + f[1]); const o = t.length, r = Xt(o), i = e.map(f => f[0]).join(","), a = e.map((f, m) => f[0] + t[m]).join(","), c = De("rc", o), l = De("source", o), u = `${c[o - 1]} < ${this.outputShape[o - 1]}`, d = o === 1 ? "source" : `vec2(${l.slice(-2).join()})`, h = s === "reflect" ? 0 : 1; let p = ""; if (o === 1) {
                const f = `
        ${r} source = rc;
        if (source < start) {
          source = start * 2 - source - ${h};
        } else if (source >= end) {
          source = (end - 1) * 2 - source + ${h};
        }
        source -= start;
      `; p = `
        ${r} rc = outputLoc;
        ${f}
        result[0] = getChannel(getX(${l.join()}), ${d});
        ${c[o - 1]} += 1;
        if(${u}) {
          ${f}
          result[1] = getChannel(getX(${l.join()}), ${d});
        }
      `} else {
                const f = `
        ${r} source = rc;
        ${r} lt = ${r}(lessThan(source, start));
        ${r} gte = ${r}(greaterThanEqual(source, end));
        ${r} orig = 1 - (lt + gte);
        source = orig * source +
                lt * (start * 2 - source - ${h}) +
                gte * ((end - 1) * 2 - source + ${h});
        source -= start;
      `; p = `
        ${r} rc = outputLoc;
        ${f}
        result[0] = getChannel(getX(${l.join()}), ${d});
        ${c[o - 1]} += 1;
        if(${u}) {
          ${f}
          result[1] = getChannel(getX(${l.join()}), ${d});
        }
        rc = outputLoc;
        ${c[o - 2]} += 1;
        if(${c[o - 2]} < ${this.outputShape[o - 2]}) {
          ${f}
          result[2] = getChannel(getX(${l.join()}), ${d});
          ${c[o - 1]} += 1;
          if(${u}) {
            ${f}
            result[3] = getChannel(getX(${l.join()}), ${d});
          }
        }
      `} this.userCode = `
      const ${r} start = ${r}(${i});
      const ${r} end = ${r}(${a});

      void main() {
        ${r} outputLoc = getOutputCoords();
        vec4 result = vec4(0.);
        ${p}
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const pK = { kernelName: _a, backendName: "webgl", kernelFunc: ({ inputs: n, backend: t, attrs: e }) => { const { x: s } = n, { paddings: o, mode: r } = e, i = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new hK(s.shape, o, r) : new dK(s.shape, o, r); return t.runWebGLProgram(i, [s], s.dtype) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const fK = `if (b == 0.0) return NAN;
  return mod(a, b);`, mK = `
  vec4 result = mod(a, b);
  bvec4 isNaN = equal(b, vec4(0.0));
  `+ ea + `
  return result;
`, gK = we({ opSnippet: fK, packedOpSnippet: mK }), bK = { kernelName: _r, backendName: "webgl", kernelFunc: gK };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class xK {
        constructor(t, e, s) {
            this.variableNames = ["probs"], this.customUniforms = [{ name: "seed", type: "float" }], this.outputShape = [t, s], this.userCode = `
      void main() {
        ivec2 coords = getOutputCoords();
        int batch = coords[0];

        float r = random(seed);
        float cdf = 0.0;

        for (int i = 0; i < ${e - 1}; i++) {
          cdf += getProbs(batch, i);

          if (r < cdf) {
            setOutput(float(i));
            return;
          }
        }

        // If no other event happened, last event happened.
        setOutput(float(${e - 1}));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const Q1 = we({
        opSnippet: `
if (a == b) {
  return 1.0;
};
return a / b;`, packedOpSnippet: `
  // vec4 one = vec4(equal(a, b));
  // return one + (vec4(1.0) - one) * a / b;
  vec4 result = a / b;
  if(a.x == b.x) {
    result.x = 1.;
  }
  if(a.y == b.y) {
    result.y = 1.;
  }
  if(a.z == b.z) {
    result.z = 1.;
  }
  if(a.w == b.w) {
    result.w = 1.;
  }

  return result;
`, checkOutOfBounds: !0
    }), yK = { kernelName: Lr, backendName: "webgl", kernelFunc: Q1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const J1 = "return a - b;", j1 = we({ opSnippet: J1, packedOpSnippet: J1, supportsComplex: !0, cpuKernelImpl: qV }), IK = { kernelName: li, backendName: "webgl", kernelFunc: j1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function q1(n) { const { inputs: t, backend: e, attrs: s } = n, { logits: o } = t, { dim: r } = s, i = It([r], o.shape), a = Y1({ inputs: { x: o }, backend: e, attrs: { reductionIndices: i, keepDims: !1 } }), c = oe(a.shape, i), l = et({ inputs: { x: a }, backend: e, attrs: { shape: c } }), u = j1({ inputs: { a: o, b: l }, backend: e }), d = K1({ inputs: { x: u }, backend: e }), h = Tl({ inputs: { x: d }, backend: e, attrs: { axis: i, keepDims: !1 } }), p = et({ inputs: { x: h }, backend: e, attrs: { shape: c } }), f = Q1({ inputs: { a: d, b: p }, backend: e }); return e.disposeIntermediateTensorInfo(a), e.disposeIntermediateTensorInfo(l), e.disposeIntermediateTensorInfo(u), e.disposeIntermediateTensorInfo(d), e.disposeIntermediateTensorInfo(h), e.disposeIntermediateTensorInfo(p), f } const CK = { kernelName: dc, backendName: "webgl", kernelFunc: q1 };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function wK(n) { const { inputs: t, backend: e, attrs: s } = n, { logits: o } = t, { numSamples: r, seed: i, normalized: a } = s, c = a ? o : q1({ inputs: { logits: o }, backend: e, attrs: { dim: o.shape.length - 1 } }), l = c.shape[0], u = c.shape[1], d = new xK(l, u, r), h = [[i]], p = e.runWebGLProgram(d, [c], "int32", h); return a || e.disposeIntermediateTensorInfo(c), p } const vK = { kernelName: bf, backendName: "webgl", kernelFunc: wK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const SK = Cn + `
  return -x;
`, kK = `
  vec4 result = -x;
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`; function TK(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (e.shouldExecuteOnCPU([s])) { const r = e.texData.get(s.dataId), [i, a] = MV(r.values, s.shape, s.dtype); return e.makeTensorInfo(a, s.dtype, i) } let o; return A().getBool("WEBGL_PACK_UNARY_OPERATIONS") ? o = new Ds(s.shape, kK) : o = new Yn(s.shape, SK), e.runWebGLProgram(o, [s], s.dtype) } const NK = { kernelName: Ua, backendName: "webgl", kernelFunc: TK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const RK = Ad; function $K(n) { Qe("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"); const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c } = s, l = e.readSync(o.dataId), u = e.readSync(r.dataId), { selectedIndices: d } = RK(l, u, i, a, c); return e.makeTensorInfo([d.length], "int32", new Int32Array(d)) } const GK = { kernelName: ku, backendName: "webgl", kernelFunc: $K };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const LK = Od; function EK(n) { Qe("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"); const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c, padToMaxOutputSize: l } = s, u = e.readSync(o.dataId), d = e.readSync(r.dataId), { selectedIndices: h, validOutputs: p } = LK(u, d, i, a, c, l); return [e.makeTensorInfo([h.length], "int32", new Int32Array(h)), e.makeTensorInfo([], "int32", new Int32Array([p]))] } const DK = { kernelName: Tu, backendName: "webgl", kernelFunc: EK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const WK = Pd; function MK(n) { Qe("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"); const { inputs: t, backend: e, attrs: s } = n, { boxes: o, scores: r } = t, { maxOutputSize: i, iouThreshold: a, scoreThreshold: c, softNmsSigma: l } = s, u = e.readSync(o.dataId), d = e.readSync(r.dataId), h = i, p = a, f = c, m = l, { selectedIndices: g, selectedScores: b } = WK(u, d, h, p, f, m); return [e.makeTensorInfo([g.length], "int32", new Int32Array(g)), e.makeTensorInfo([b.length], "float32", new Float32Array(b))] } const FK = { kernelName: Nu, backendName: "webgl", kernelFunc: MK };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class VK {
        constructor(t, e, s, o) {
            this.variableNames = ["indices"], this.outputShape = [t, e], this.userCode = `
      void main() {
        ivec2 coords = getOutputCoords();
        int index = round(getIndices(coords.x));
        setOutput(mix(float(${o}), float(${s}),
                      float(index == coords.y)));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zK = { kernelName: Ja, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { indices: o } = t, { dtype: r, depth: i, onValue: a, offValue: c } = s, l = Z(o.shape), u = new VK(l, i, a, c), d = et({ inputs: { x: o }, backend: e, attrs: { shape: [l] } }), h = e.runWebGLProgram(u, [d], r); e.disposeIntermediateTensorInfo(d); const p = [...o.shape, i], f = et({ inputs: { x: h }, backend: e, attrs: { shape: p } }); return e.disposeIntermediateTensorInfo(h), f } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function El(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (s.dtype === "complex64") { const o = ra({ inputs: { input: s }, backend: e }), r = El({ inputs: { x: o }, backend: e }), i = Gl({ inputs: { input: s }, backend: e }), a = El({ inputs: { x: i }, backend: e }), c = Ws({ inputs: { real: r, imag: a }, backend: e }); return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(r), e.disposeIntermediateTensorInfo(i), e.disposeIntermediateTensorInfo(a), c } else return ca({ attrs: { shape: s.shape, dtype: s.dtype, value: s.dtype === "string" ? "" : 0 }, backend: e }) } const XK = { kernelName: fc, backendName: "webgl", kernelFunc: El };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tI(n) { const { inputs: t, backend: e } = n, { x: s } = t; if (s.dtype === "string") throw new Error("onesLike is not supported under string dtype"); if (s.dtype === "complex64") { const o = ra({ inputs: { input: s }, backend: e }), r = tI({ inputs: { x: o }, backend: e }), i = Gl({ inputs: { input: s }, backend: e }), a = El({ inputs: { x: i }, backend: e }), c = Ws({ inputs: { real: r, imag: a }, backend: e }); return e.disposeIntermediateTensorInfo(o), e.disposeIntermediateTensorInfo(r), e.disposeIntermediateTensorInfo(i), e.disposeIntermediateTensorInfo(a), c } else return ca({ attrs: { shape: s.shape, dtype: s.dtype, value: 1 }, backend: e }) } const AK = { kernelName: Qa, backendName: "webgl", kernelFunc: tI };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function OK(n) { const { inputs: t, backend: e, attrs: s } = n, { axis: o } = s; if (t.length === 1) return Gp({ inputs: { input: t[0] }, backend: e, attrs: { dim: o } }); const r = t[0].shape, i = t[0].dtype; t.forEach(u => { Pl(r, u.shape, "All tensors passed to stack must have matching shapes"), v(i === u.dtype, () => "All tensors passed to stack must have matching dtypes") }); const a = [], c = t.map(u => { const d = Gp({ inputs: { input: u }, backend: e, attrs: { dim: o } }); return a.push(d), d }), l = E1({ inputs: c, backend: e, attrs: { axis: o } }); return a.forEach(u => e.disposeIntermediateTensorInfo(u)), l } const PK = { kernelName: ja, backendName: "webgl", kernelFunc: OK };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class KK {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.customUniforms = [{ name: "value", type: "float" }], this.outputShape = e.map((l, u) => l[0] + t[u] + l[1]); const o = t.length, r = Xt(o), i = e.map(l => l[0]).join(","), a = e.map((l, u) => l[0] + t[u]).join(","), c = ["coords[0]", "coords[1]", "coords[2]", "coords[3]"].slice(0, o); if (o === 1) {
                this.userCode = `
        int start = ${i};
        int end = ${a};

        void main() {
          int outC = getOutputCoords();
          if (outC < start || outC >= end) {
            setOutput(value);
          } else {
            setOutput(getX(outC - start));
          }
        }
      `; return
            } this.userCode = `
      ${r} start = ${r}(${i});
      ${r} end = ${r}(${a});

      void main() {
        ${r} outC = getOutputCoords();
        if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {
          setOutput(value);
        } else {
          ${r} coords = outC - start;
          setOutput(getX(${c}));
        }
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class ZK {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "value", type: "float" }], this.outputShape = e.map((m, g) => m[0] + t[g] + m[1]); const o = t.length, r = Xt(o), i = e.map(m => m[0]).join(","), a = e.map((m, g) => m[0] + t[g]).join(","), c = De("rc", o), l = De("source", o), u = `${c[o - 1]} < ${this.outputShape[o - 1]}`, d = o === 1 ? "source" : `vec2(${l.slice(-2).join()})`, h = [`${r} rc = outputLoc;`, `${c[o - 1]} += 1;
       if(${u}) {
      `, o === 1 ? "" : `}
       rc = outputLoc;
       ${c[o - 2]} += 1;
       if(${c[o - 2]} < ${this.outputShape[o - 2]}) {`, o === 1 ? "" : `  ${c[o - 1]} += 1;
         if(${u}) {`], p = o === 1 ? "rc < start || rc >= end" : "any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))"; let f = ""; for (let m = 0, g = o === 1 ? 2 : 4; m < g; m++)f += `
        ${h[m]}
        if (${p}) {
          result[${m}] = float(value);
        } else {
          ${r} source = rc - start;
          result[${m}] = getChannel(getX(${l.join()}), ${d});
        }
      `; f += o === 1 ? "} " : "}}", this.userCode = `
      const ${r} start = ${r}(${i});
      const ${r} end = ${r}(${a});

      void main() {
        ${r} outputLoc = getOutputCoords();
        vec4 result = vec4(0.);
        ${f}
        setOutput(result);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const eI = n => { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { paddings: r, constantValue: i } = s; if (Z(o.shape) === 0) { const l = r.map((u, d) => u[0] + o.shape[d] + u[1]); return ca({ backend: e, attrs: { shape: l, value: i, dtype: o.dtype } }) } const a = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new ZK(o.shape, r, i) : new KK(o.shape, r, i), c = [[i]]; return e.runWebGLProgram(a, [o], o.dtype, c) }, BK = { kernelName: qa, backendName: "webgl", kernelFunc: eI };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const HK = `
  if(a < 0.0 && floor(b) < b){
    return NAN;
  }
  if (b == 0.0) {
    return 1.0;
  }
  return (round(mod(b, 2.0)) != 1) ?
      pow(abs(a), b) : sign(a) * pow(abs(a), b);
`, _K = `
  // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
  vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));
  vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);
  vec4 result = multiplier * pow(abs(a), b);

  // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
  bvec4 isExpZero = equal(b, vec4(0.0));
  result.r = isExpZero.r ? 1.0 : result.r;
  result.g = isExpZero.g ? 1.0 : result.g;
  result.b = isExpZero.b ? 1.0 : result.b;
  result.a = isExpZero.a ? 1.0 : result.a;

  bvec4 isNaN1 = lessThan(a, vec4(0.0));
  bvec4 isNaN2 = lessThan(floor(b), b);
  bvec4 isNaN = bvec4(isNaN1.x && isNaN2.x, isNaN1.y && isNaN2.y, isNaN1.z && isNaN2.z, isNaN1.w && isNaN2.w);
  `+ ea + `
  return result;
`, UK = we({ opSnippet: HK, packedOpSnippet: _K }), YK = { kernelName: Yr, backendName: "webgl", kernelFunc: UK };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QK(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { axis: r, keepDims: i } = s, a = o.shape.length, c = [], l = It(r, o.shape); let u = l; const d = Yt(u, a); let h = o; d != null && (h = We({ inputs: { x: o }, backend: e, attrs: { perm: d } }), u = te(u.length, a), c.push(h)), Ie("prod", u, a); let p; if (e.shouldExecuteOnCPU([h])) { const f = e.texData.get(h.dataId).values, { outVals: m, outShape: g, outDtype: b } = VV(h.shape, h.dtype, f, u); p = e.makeTensorInfo(g, b, m) } else { const [f, m] = fe(h.shape, u), g = Z(m), b = et({ inputs: { x: h }, backend: e, attrs: { shape: [-1, g] } }), x = Yu(o.dtype), I = wo(b, x, "prod", e); p = et({ inputs: { x: I }, backend: e, attrs: { shape: f } }), c.push(b), c.push(I) } if (i) { c.push(p); const f = oe(p.shape, l); p = et({ inputs: { x: p }, backend: e, attrs: { shape: f } }) } return c.forEach(f => e.disposeIntermediateTensorInfo(f)), p } const JK = { kernelName: ec, backendName: "webgl", kernelFunc: QK };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jK(n) { const { inputs: t, backend: e, attrs: s } = n, { paramsNestedSplits: o, paramsDenseValues: r, indices: i } = t, { outputRaggedRank: a } = s, c = o.map(b => e.readSync(b.dataId)), l = o.map(b => b.shape), u = e.readSync(r.dataId), d = e.readSync(i.dataId), [h, p, f] = zV(c, l, u, r.shape, r.dtype, d, i.shape, a), m = h.map(b => e.makeTensorInfo([b.length], "int32", b)), g = e.makeTensorInfo(f, r.dtype, p); return m.concat([g]) } const qK = { kernelName: xf, backendName: "webgl", kernelFunc: jK };/**
 * @license
 * Copyright 2022 Google LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function tZ(n) { const { inputs: t, backend: e } = n, { starts: s, limits: o, deltas: r } = t, i = e.readSync(s.dataId), a = e.readSync(o.dataId), c = e.readSync(r.dataId), [l, u] = XV(i, s.shape, s.dtype, a, o.shape, c, r.shape), d = e.makeTensorInfo([l.length], "int32", l), h = e.makeTensorInfo([u.length], s.dtype, u); return [d, h] } const eZ = { kernelName: yf, backendName: "webgl", kernelFunc: tZ };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function nZ(n) { const { inputs: t, backend: e, attrs: s } = n, { shape: o, values: r, defaultValue: i, rowPartitionTensors: a } = t, { rowPartitionTypes: c } = s, l = e.readSync(o.dataId), u = e.readSync(r.dataId), d = e.readSync(i.dataId), h = a.map(g => e.readSync(g.dataId)), p = a.map(g => g.shape), [f, m] = AV(l, o.shape, u, r.shape, r.dtype, d, i.shape, h, p, c); return e.makeTensorInfo(f, r.dtype, m) } const sZ = { kernelName: If, backendName: "webgl", kernelFunc: nZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const nI = n => { const { backend: t, attrs: e } = n, { start: s, stop: o, step: r, dtype: i } = e, a = OV(s, o, r, i); return t.makeTensorInfo([a.length], i, a) }, oZ = { kernelName: Ru, backendName: "webgl", kernelFunc: nI };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rZ = Tt({ opSnippet: "return 1.0 / x;" }), iZ = { kernelName: Qr, backendName: "webgl", kernelFunc: rZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const aZ = Cn + `
  return (x < 0.0) ? 0.0 : x;
`, cZ = Tt({
        opSnippet: aZ, packedOpSnippet: `
  vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`}), lZ = { kernelName: Jr, backendName: "webgl", kernelFunc: cZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const uZ = Cn + `
  return (x < 0.0) ? 0.0 : min(6.0, x);
`, dZ = Tt({
            opSnippet: uZ, packedOpSnippet: `
  vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`}), hZ = { kernelName: jr, backendName: "webgl", kernelFunc: dZ };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class pZ {
        constructor(t, e, s, o, r) {
            this.variableNames = ["A"], this.outputShape = []; const [i, a, c, l] = t; this.outputShape = [i, e, s, l]; const u = [o && e > 1 ? a - 1 : a, o && s > 1 ? c - 1 : c], d = [o && e > 1 ? e - 1 : e, o && s > 1 ? s - 1 : s]; let h; r ? h = "(vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC - vec2(0.5)" : h = "vec2(yRC) * effectiveInputOverOutputRatioRC", this.userCode = `
      const vec2 effectiveInputOverOutputRatioRC = vec2(
          ${u[0] / d[0]},
          ${u[1] / d[1]});
      const vec2 inputShapeRC = vec2(${a}.0, ${c}.0);

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        ivec2 yRC = coords.yz;

        // Fractional source index.
        vec2 sourceFracIndexRC = ${h};

        // Compute the four integer indices.
        ivec2 sourceFloorRC = ivec2(max(sourceFracIndexRC, vec2(0.0)));
        ivec2 sourceCeilRC = ivec2(
          min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));

        float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);
        float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);
        float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);
        float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);

        vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);

        float top = topLeft + (topRight - topLeft) * fracRC.y;
        float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;
        float newValue = top + (bottom - top) * fracRC.x;

        setOutput(newValue);
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class fZ {
        constructor(t, e, s, o, r) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = []; const [i, a, c, l] = t; this.outputShape = [i, e, s, l]; const u = [o && e > 1 ? a - 1 : a, o && s > 1 ? c - 1 : c], d = [o && e > 1 ? e - 1 : e, o && s > 1 ? s - 1 : s]; let h; r ? h = "(vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC - vec3(0.5)" : h = "vec3(yRC) * effectiveInputOverOutputRatioRC", this.userCode = `
      const vec3 effectiveInputOverOutputRatioRC = vec3(
          ${u[0] / d[0]},
          ${u[1] / d[1]},
          ${u[1] / d[1]});
      const vec3 inputShapeRC = vec3(${a}.0, ${c}.0,
                                     ${c}.0);

      float getAValue(int b, int r, int c, int d) {
        return getChannel(getA(b, r, c, d), vec2(c, d));
      }

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        // Calculate values for next column in yRC.z.
        ivec3 yRC = coords.yzz + ivec3(0, 0, 1);

        // Fractional source index.
        vec3 sourceFracIndexRC = ${h};

        // Compute the four integer indices.
        ivec3 sourceFloorRC = ivec3(max(sourceFracIndexRC, vec3(0.0)));
        ivec3 sourceCeilRC = ivec3(
          min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));

        // Should we calculate next column and row elements in 2x2 packed cell.
        bool hasNextCol = d < ${l - 1};
        bool hasNextRow = coords.z < ${s - 1};

        // In parallel, construct four corners for all four components in
        // packed 2x2 cell.
        vec4 topLeft = vec4(
          getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),
          hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)
                     : 0.0,
          hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)
                     : 0.0,
          (hasNextRow && hasNextCol) ?
            getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);

        vec4 bottomLeft = vec4(
          getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),
          hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)
                     : 0.0,
          hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)
                     : 0.0,
          (hasNextRow && hasNextCol) ?
            getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);

        vec4 topRight = vec4(
          getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),
          hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)
                     : 0.0,
          hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)
                     : 0.0,
          (hasNextRow && hasNextCol) ?
            getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);

        vec4 bottomRight = vec4(
          getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),
          hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)
                     : 0.0,
          hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)
                     : 0.0,
          (hasNextRow && hasNextCol) ?
            getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);

        vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);

        vec4 top = mix(topLeft, topRight, fracRC.yyzz);
        vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);
        vec4 newValue = mix(top, bottom, fracRC.x);

        setOutput(newValue);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mZ(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o } = t, { alignCorners: r, halfPixelCenters: i, size: a } = s, [c, l] = a, u = A().getBool("WEBGL_PACK_IMAGE_OPERATIONS") ? new fZ(o.shape, c, l, r, i) : new pZ(o.shape, c, l, r, i); return e.runWebGLProgram(u, [o], "float32") } const gZ = { kernelName: oc, backendName: "webgl", kernelFunc: mZ };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class bZ {
        constructor(t, e, s) {
            this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e; const [, o, r] = e, [, i, a] = t, c = [s && i > 1 ? o - 1 : o, s && a > 1 ? r - 1 : r], l = [s && i > 1 ? i - 1 : i, s && a > 1 ? a - 1 : a], u = c[0] / l[0], d = c[1] / l[1], h = 1 / u, p = 1 / d, f = Math.ceil(h) * 2 + 2, m = Math.ceil(p) * 2 + 2; this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        int r = coords[1];
        int c = coords[2];

        float accumulator = 0.0;

        const float heightScale = float(${u});
        const float widthScale = float(${d});

        const float invHeightScale = float(${h});
        const float invWidthScale = float(${p});

        const int winHeight = int(${f});
        const int winWidth = int(${m});

        // Compute bounds for where in dy we will look
        float startRLerp = floor(float(r) * invHeightScale);
        int startDyR = int(startRLerp - float(winHeight / 2));

        float startCLerp = floor(float(c) * invWidthScale);
        int startDyC = int(startCLerp - float(winWidth / 2));

        // Loop over dy
        for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
          int dyR = dyROffset + startDyR;

          // Guard against the window exceeding the bounds of dy
          if (dyR < 0 || dyR >= ${i}) {
            continue;
          }

          for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
            int dyC = dyCOffset + startDyC;

            // Guard against the window exceeding the bounds of dy
            if (dyC < 0 || dyC >= ${a}) {
              continue;
            }

            float dxR = float(dyR) * heightScale;
            int topDxRIndex = int(floor(dxR));
            int bottomDxRIndex = int(min(ceil(dxR), ${o - 1}.0));
            float dxRLerp = dxR - float(topDxRIndex);
            float inverseDxRLerp = 1.0 - dxRLerp;

            float dxC = float(dyC) * widthScale;
            int leftDxCIndex = int(floor(dxC));
            int rightDxCIndex = int(min(ceil(dxC), ${r - 1}.0));
            float dxCLerp = dxC - float(leftDxCIndex);
            float inverseDxCLerp = 1.0 - dxCLerp;

            if (r == topDxRIndex && c == leftDxCIndex) {
              // topLeft
              accumulator +=
                getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;
            }

            if (r == topDxRIndex && c == rightDxCIndex) {
              // topRight
              accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;
            }

            if (r == bottomDxRIndex && c == leftDxCIndex) {
              // bottomLeft
              accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;
            }

            if (r == bottomDxRIndex && c == rightDxCIndex) {
              // bottomRight
              accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;
            }
          }
        }
        // End loop over dy

        setOutput(accumulator);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function xZ(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o, dy: r } = t, { alignCorners: i } = s, a = new bZ(r.shape, o.shape, i); return e.runWebGLProgram(a, [r], r.dtype) } const yZ = { kernelName: Lu, backendName: "webgl", kernelFunc: xZ };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class IZ {
        constructor(t, e, s, o, r) {
            this.variableNames = ["A"], this.outputShape = []; const [i, a, c, l] = t; this.outputShape = [i, e, s, l]; const u = [o && e > 1 ? a - 1 : a, o && s > 1 ? c - 1 : c], d = [o && e > 1 ? e - 1 : e, o && s > 1 ? s - 1 : s], h = o ? "0.5" : "0.0"; let p; r ? p = "max((vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC, vec2(0.0))" : p = "vec2(yRC) * effectiveInputOverOutputRatioRC", this.userCode = `
      const vec2 effectiveInputOverOutputRatioRC = vec2(
          ${u[0] / d[0]},
          ${u[1] / d[1]});
      const vec2 inputShapeRC = vec2(${a}.0, ${c}.0);

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        ivec2 yRC = coords.yz;

        // Fractional source index.
        vec2 sourceFracIndexRC = ${p};

        // Compute the coordinators of nearest neighbor point.
        ivec2 sourceNearestRC = ivec2(
          min(inputShapeRC - 1.0, floor(sourceFracIndexRC + ${h})));
        float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);

        setOutput(newValue);
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class CZ {
        constructor(t, e, s, o, r) {
            this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = []; const [i, a, c, l] = t; this.outputShape = [i, e, s, l]; const u = [o && e > 1 ? a - 1 : a, o && s > 1 ? c - 1 : c], d = [o && e > 1 ? e - 1 : e, o && s > 1 ? s - 1 : s], h = o ? "0.5" : "0.0"; let p; r ? p = "max((vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC, vec3(0.0))" : p = "vec3(yRC) * effectiveInputOverOutputRatioRC", this.userCode = `
      const vec3 effectiveInputOverOutputRatioRC = vec3(
          ${u[0] / d[0]},
          ${u[1] / d[1]},
          ${u[1] / d[1]});
      const vec3 inputShapeRC = vec3(${a}.0, ${c}.0,
                                     ${c}.0);

      float getAValue(int b, int r, int c, int d) {
        return getChannel(getA(b, r, c, d), vec2(c, d));
      }

      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        // Calculate values for next column in yRC.z.
        ivec3 yRC = coords.yzz + ivec3(0, 0, 1);

        // Fractional source index.
        vec3 sourceFracIndexRC = ${p};

        // Compute the coordinators of nearest neighbor point.
        ivec3 sourceNearestRC = ivec3(
          min(inputShapeRC - 1.0, floor(sourceFracIndexRC + ${h})));

        // Should we calculate next column and row elements in 2x2 packed cell.
        bool hasNextCol = d < ${l - 1};
        bool hasNextRow = coords.z < ${s - 1};

        vec4 newValue = vec4(
          getAValue(b, sourceNearestRC.x, sourceNearestRC.y, d),
          hasNextCol ? getAValue(b, sourceNearestRC.x, sourceNearestRC.y, d + 1)
                     : 0.0,
          hasNextRow ? getAValue(b, sourceNearestRC.x, sourceNearestRC.z, d)
                     : 0.0,
          (hasNextRow && hasNextCol) ?
            getAValue(b, sourceNearestRC.x, sourceNearestRC.z, d + 1) : 0.0);

        setOutput(newValue);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function wZ(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o } = t, { alignCorners: r, halfPixelCenters: i, size: a } = s, [c, l] = a, u = A().getBool("WEBGL_PACK_IMAGE_OPERATIONS") ? new CZ(o.shape, c, l, r, i) : new IZ(o.shape, c, l, r, i); return e.runWebGLProgram(u, [o], o.dtype) } const vZ = { kernelName: sc, backendName: "webgl", kernelFunc: wZ };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class SZ {
        constructor(t, e, s) {
            this.variableNames = ["dy"], this.outputShape = [], this.outputShape = e; const [, o, r] = e, [, i, a] = t, c = [s && i > 1 ? o - 1 : o, s && a > 1 ? r - 1 : r], l = [s && i > 1 ? i - 1 : i, s && a > 1 ? a - 1 : a], u = c[0] / l[0], d = c[1] / l[1], h = 1 / u, p = 1 / d, f = Math.ceil(h) * 2 + 2, m = Math.ceil(p) * 2 + 2; this.userCode = `
      void main() {
        ivec4 coords = getOutputCoords();
        int b = coords[0];
        int d = coords[3];
        int r = coords[1];
        int c = coords[2];

        float accumulator = 0.0;

        const float heightScale = float(${u});
        const float widthScale = float(${d});

        const float invHeightScale = float(${h});
        const float invWidthScale = float(${p});

        const int winHeight = int(${f});
        const int winWidth = int(${m});

        // Compute bounds for where in dy we will look
        float startRLerp = floor(float(r) * invHeightScale);
        int startDyR = int(floor(startRLerp - float(winHeight / 2)));

        float startCLerp = floor(float(c) * invWidthScale);
        int startDyC = int(floor(startCLerp - float(winWidth / 2)));

        // Loop over dy
        for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {
          int dyR = dyROffset + startDyR;

          // Guard against the window exceeding the bounds of dy
          if (dyR < 0 || dyR >= ${i}) {
            continue;
          }

          for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {
            int dyC = dyCOffset + startDyC;

            // Guard against the window exceeding the bounds of dy
            if (dyC < 0 || dyC >= ${a}) {
              continue;
            }

            float sourceFracRow =
              float(${c[0]}) *
                (float(dyR) / float(${l[0]}));

            float sourceFracCol =
                float(${c[1]}) *
                  (float(dyC) / float(${l[1]}));

            int sourceNearestRow = int(min(
                float(int(${o}) - 1),
                ${s} ? float(round(sourceFracRow)) :
                                  float(floor(sourceFracRow))));

            int sourceNearestCol = int(min(
                float(int(${r}) - 1),
                ${s} ? float(round(sourceFracCol)) :
                                  float(floor(sourceFracCol))));

            if (r == sourceNearestRow && c == sourceNearestCol) {
              accumulator += getDy(b, dyR, dyC, d);
            }
          }
        }
        // End loop over dy

        setOutput(accumulator);
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kZ(n) { const { inputs: t, backend: e, attrs: s } = n, { images: o, dy: r } = t, { alignCorners: i } = s, a = new SZ(r.shape, o.shape, i); return e.runWebGLProgram(a, [r], r.dtype) } const TZ = { kernelName: Gu, backendName: "webgl", kernelFunc: kZ };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class NZ {
        constructor(t, e) {
            this.variableNames = ["x"]; const s = t.length; if (s > 4) throw new Error(`WebGL backend: Reverse of rank-${s} tensor is not yet supported`); if (this.outputShape = t, s === 1) {
                this.userCode = `
        void main() {
          int coord = getOutputCoords();
          setOutput(getX(${t[0]} - coord - 1));
        }
      `; return
            } const o = a => e.indexOf(a) !== -1 && t[a] !== 1 ? `${t[a]} - coords[${a}] - 1` : `coords[${a}]`, r = t.map((a, c) => o(c)).join(","), i = Xt(s); this.userCode = `
      void main() {
        ${i} coords = getOutputCoords();
        setOutput(getX(${r}));
      }
    `}
    }/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class RZ {
        constructor(t, e) {
            this.variableNames = ["x"], this.packedInputs = !0, this.packedOutput = !0; const s = t.length; if (s > 4) throw new Error(`WebGL backend: Reverse of rank-${s} tensor is not yet supported`); this.outputShape = t; const o = De("rc", s), r = `${o[s - 1]} + 1 < ${this.outputShape[s - 1]}`, i = `${o[s - 2]} + 1 < ${this.outputShape[s - 2]}`, a = Xt(s); s === 1 ? this.userCode = `
        void main(){
          int rc = getOutputCoords();
          vec4 result = vec4(0.);
          result.r = getChannel(getX(${t[0]} - rc - 1),
            ${t[0]} - rc - 1);
          if(${r}){
              result.g = getChannel(getX(${t[0]} - (rc  + 1) - 1),
                ${t[0]} - (rc  + 1) - 1);
          }
          setOutput(result);
        }
      `: this.userCode = `
        void main() {
          ${a} rc = getOutputCoords();
          vec4 result = vec4(0.);
          result.r = ${c(o.slice())};
          if(${r}){
            result.g = ${l(o.slice())};
          }
          if(${i}) {
            result.b = ${u(o.slice())};
            if(${r}) {
              result.a = ${d(o.slice())};
            }
          }
          setOutput(result);
        }
    `; function c(f) { return h(f) } function l(f) { return f[s - 1] = "(" + f[s - 1] + " + 1)", h(f) } function u(f) { return f[s - 2] = "(" + f[s - 2] + " + 1)", h(f) } function d(f) { return f[s - 1] = "(" + f[s - 1] + " + 1)", f[s - 2] = "(" + f[s - 2] + " + 1)", h(f) } function h(f) { const m = t.map((x, I) => p(I, f)), g = m.join(","), b = m.slice(-2).join(","); return `getChannel(getX(${g}), vec2(${b}))` } function p(f, m) { return e.indexOf(f) !== -1 && t[f] !== 1 ? `${t[f]} - ${m[f]} - 1` : `${m[f]}` }
        }
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function $Z(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { dims: r } = s, i = o.shape.length, a = It(r, o.shape); if (i === 0) return Ye({ inputs: { x: o }, backend: e }); const c = A().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new RZ(o.shape, a) : new NZ(o.shape, a); return e.runWebGLProgram(c, [o], o.dtype) } const GZ = { kernelName: rc, backendName: "webgl", kernelFunc: $Z };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class LZ {
        constructor(t, e) {
            this.variableNames = ["Image"], this.outputShape = [], this.customUniforms = [{ name: "params", type: "vec4" }]; const s = t[1], o = t[2]; this.outputShape = t; let r = ""; typeof e == "number" ? r = `float outputValue = ${e.toFixed(2)};` : r = `
        vec3 fill = vec3(${e.join(",")});
        float outputValue = fill[coords[3]];`, this.userCode = `
        void main() {
          ivec4 coords = getOutputCoords();
          int x = coords[2];
          int y = coords[1];
          float coordXFloat = (float(x) - params[0]) * params[3] -
            (float(y) - params[1]) * params[2];
          float coordYFloat = (float(x) - params[0]) * params[2] +
            (float(y) - params[1]) * params[3];
          int coordX = int(round(coordXFloat + params[0]));
          int coordY = int(round(coordYFloat + params[1]));
          ${r}
          if(coordX >= 0 && coordX < ${o} && coordY >= 0 && coordY < ${s}) {
            outputValue = getImage(coords[0], coordY, coordX, coords[3]);
          }
          setOutput(outputValue);
        }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const EZ = { kernelName: zu, backendName: "webgl", kernelFunc: ({ inputs: n, attrs: t, backend: e }) => { const { image: s } = n, { radians: o, fillValue: r, center: i } = t, a = e, c = new LZ(s.shape, r), [l, u] = th(i, s.shape[1], s.shape[2]), d = [[l, u, Math.sin(o), Math.cos(o)]]; return a.runWebGLProgram(c, [s], s.dtype, d) } };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const DZ = Tt({
        opSnippet: `
  // OpenGL ES does not support round function.
  // The algorithm is based on banker's rounding.
  float base = floor(x);
  if ((x - base) < 0.5) {
    return floor(x);
  } else if ((x - base) > 0.5) {
    return ceil(x);
  } else {
    if (mod(base, 2.0) == 0.0) {
      return base;
    } else {
      return base + 1.0;
    }
  }
`}), WZ = { kernelName: qr, backendName: "webgl", kernelFunc: DZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const MZ = Tt({ opSnippet: "return inversesqrt(x);", cpuKernelImpl: PV }), FZ = { kernelName: ti, backendName: "webgl", kernelFunc: MZ };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class sI {
        constructor(t, e, s, o, r, i, a = !0) {
            this.variableNames = ["updates", "indices", "defaultValue"], this.outputShape = i; const c = Xt(r.length), l = Xt(i.length); let u = ""; s === 1 ? u = "i" : s === 2 && (u = "i, j"); const d = `getIndices(${u})`; let h = ""; o === 1 ? h = "i" : o === 2 && (h = "i, coords[1]"); const p = `getUpdates(${h})`, f = e > 1 ? "strides[j]" : "strides"; this.userCode = `
        ${c} strides = ${c}(${r});

        void main() {
          ${l} coords = getOutputCoords();
          float sum = 0.0;
          bool found = false;
          for (int i = 0; i < ${t}; i++) {
            int flattenedIndex = 0;
            for (int j = 0; j < ${e}; j++) {
              int index = round(${d});
              flattenedIndex += index * ${f};
            }
            if (flattenedIndex == coords[0]) {
              sum += ${p};
              found = true;
            }
          }
          setOutput(mix(getDefaultValue(), sum, float(found)));
        }
      `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function VZ(n) { const { inputs: t, backend: e, attrs: s } = n, { indices: o, updates: r } = t, { shape: i } = s, { sliceRank: a, numUpdates: c, sliceSize: l, strides: u, outputSize: d } = Ri(r, o, i), h = [d / l, l]; if (d === 0) return e.makeTensorInfo(i, o.dtype); const p = et({ inputs: { x: o }, backend: e, attrs: { shape: [c, a] } }), f = et({ inputs: { x: r }, backend: e, attrs: { shape: [c, l] } }), m = e.makeTensorInfo([], "float32", new Float32Array([0])), g = new sI(c, a, p.shape.length, f.shape.length, u, h), b = e.runWebGLProgram(g, [f, p, m], f.dtype), x = et({ inputs: { x: b }, backend: e, attrs: { shape: i } }); return e.disposeIntermediateTensorInfo(p), e.disposeIntermediateTensorInfo(f), e.disposeIntermediateTensorInfo(b), e.disposeIntermediateTensorInfo(m), x } const zZ = { kernelName: Cf, backendName: "webgl", kernelFunc: VZ };/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class XZ {
        constructor(t, e, s, o) {
            this.variableNames = ["sortedSequence", "values"], this.customUniforms = [{ name: "numInputs", type: "int" }], this.outputShape = [t, s]; const r = "while (left < right) {", i = `for (int i = 0; i < ${Math.ceil(Math.log2(e + 1))}; ++i) { if (left >= right) break;`, a = A().getNumber("WEBGL_VERSION") === 2 ? r : i, c = o === "left" ? "<" : "<="; this.userCode = `
       int findBound(int batch, float value) {
         int left = 0;
         int right = numInputs;
         int mid;
         ${a}
           mid = (left + right) / 2;
           if (getSortedSequence(batch, mid) ${c} value) {
             left = mid + 1;
           } else {
             right = mid;
           }
         }
         return right;
       }

       void main() {
         ivec2 coords = getOutputCoords();
         int batch = coords[0];
         int valueIndex = coords[1];

         float value = getValues(batch, valueIndex);

         setOutput(float(findBound(batch, value)));
       }
     `}
    }/**
 * @license
 * Copyright 2022 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function AZ(n) { const { inputs: t, backend: e, attrs: s } = n, { sortedSequence: o, values: r } = t, { side: i } = s, a = new XZ(o.shape[0], o.shape[1], r.shape[1], i), c = [[o.shape[1]]]; return e.runWebGLProgram(a, [o, r], "int32", c) } const OZ = { kernelName: wf, backendName: "webgl", kernelFunc: AZ };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class PZ {
        constructor(t, e, s) {
            this.variableNames = ["c", "a", "b"], this.outputShape = e; let o, r; if (s > 4) throw Error(`Where for rank ${s} is not yet supported`); if (s === 1) r = "resRC", o = "resRC"; else { const a = ["resRC.x", "resRC.y", "resRC.z", "resRC.w"], c = [], l = []; for (let u = 0; u < e.length; u++)l.push(`${a[u]}`), u < t && c.push(`${a[u]}`); o = c.join(), r = l.join() } const i = Xt(s); this.userCode = `
      void main() {
        ${i} resRC = getOutputCoords();
        float cVal = getC(${o});
        if (cVal >= 1.0) {
          setOutput(getA(${r}));
        } else {
          setOutput(getB(${r}));
        }
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function KZ(n) { const { inputs: t, backend: e } = n, { condition: s, t: o, e: r } = t, i = new PZ(s.shape.length, o.shape, o.shape.length); return e.runWebGLProgram(i, [s, o, r], Ze(o.dtype, r.dtype)) } const ZZ = { kernelName: ic, backendName: "webgl", kernelFunc: KZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const BZ = `
  // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
  // see: https://arxiv.org/abs/1706.02515
  float scaleAlpha = ${Vc};
  float scale = ${zc};
  return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);
`, HZ = Tt({ opSnippet: BZ }), _Z = { kernelName: ei, backendName: "webgl", kernelFunc: HZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const UZ = hr + `
  return 1.0 / (1.0 + exp(-1.0 * x));
`, YZ = Tt({
        opSnippet: UZ, packedOpSnippet: `
  vec4 result = 1.0 / (1.0 + exp(-1.0 * x));
  bvec4 isNaN = isnan(x);

  result.r = isNaN.r ? x.r : result.r;
  result.g = isNaN.g ? x.g : result.g;
  result.b = isNaN.b ? x.b : result.b;
  result.a = isNaN.a ? x.a : result.a;

  return result;
`, cpuKernelImpl: ZV
    }), QZ = { kernelName: ri, backendName: "webgl", kernelFunc: YZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const JZ = Tt({
        opSnippet: `
  if (isnan(x)) { return 0.0; }
  return sign(x);
`}), jZ = { kernelName: oi, backendName: "webgl", kernelFunc: JZ };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const qZ = hr + `
  return sin(x);
`, tB = Tt({ opSnippet: qZ }), eB = { kernelName: ni, backendName: "webgl", kernelFunc: tB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const nB = Tt({
            opSnippet: `
  float e2x = exp(x);
  return (e2x - 1.0 / e2x) / 2.0;
`}), sB = { kernelName: si, backendName: "webgl", kernelFunc: nB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oB = Tt({
                opSnippet: `
  float epsilon = 1.1920928955078125e-7;
  float threshold = log(epsilon) + 2.0;

  bool too_large = x > -threshold;
  bool too_small = x < threshold;

  float result;
  float exp_x = exp(x);

  if (too_large){
    result = x;
  }
  else if (too_small){
    result = exp_x;
  }
  else{
    result = log(exp_x + 1.0);
  }
  return result;
`}), rB = { kernelName: ii, backendName: "webgl", kernelFunc: oB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const iB = { kernelName: lc, backendName: "webgl", kernelFunc: n => { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { blockShape: r, paddings: i } = s; v(o.shape.length <= 4, () => "spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"); const a = r.reduce((b, x) => b * x), c = [[0, 0]]; c.push(...i); for (let b = 1 + r.length; b < o.shape.length; ++b)c.push([0, 0]); const l = [], u = eI({ inputs: { x: o }, backend: e, attrs: { paddings: c, constantValue: 0 } }), d = $i(u.shape, r, a, !1), h = Gi(d.length, r.length, !1), p = Li(u.shape, r, a, !1), f = et({ inputs: { x: u }, backend: e, attrs: { shape: d } }), m = We({ inputs: { x: f }, backend: e, attrs: { perm: h } }), g = et({ inputs: { x: m }, backend: e, attrs: { shape: p } }); return l.push(u), l.push(f), l.push(m), l.forEach(b => e.disposeIntermediateTensorInfo(b)), g } };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function aB(n) {
        const { inputs: t, backend: e } = n, { indices: s, values: o, denseShape: r, defaultValue: i } = t; if (r.shape.length !== 1) throw new Error(`Dense shape must be a vector, saw:
         ${r.shape}`); if (s.shape.length !== 2) throw new Error(`Indices must be a matrix, saw:
         ${s.shape}`); if (o.shape.length !== 1) throw new Error(`Values must be a vector, saw:
         ${o.shape}`); if (i.shape.length !== 0) throw new Error(`Default value must be a scalar, saw:
        ${i.shape}`); const a = e.readSync(s.dataId), c = e.readSync(o.dataId), l = e.readSync(r.dataId), u = e.readSync(i.dataId)[0], [d, h, p, f, m] = HV(a, s.shape, s.dtype, c, o.dtype, l, u); return [e.makeTensorInfo(h, s.dtype, d), e.makeTensorInfo([h[0]], o.dtype, p), e.makeTensorInfo([f.length], "bool", new Uint8Array(f.map(g => Number(g)))), e.makeTensorInfo([m.length], s.dtype, new Int32Array(m))]
    } const cB = { kernelName: vf, backendName: "webgl", kernelFunc: aB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function lB(n) { const { inputs: t, backend: e } = n, { inputIndices: s, inputShape: o, newShape: r } = t; if (s.shape.length !== 2) throw new Error(`Input indices should be a matrix but received shape ${s.shape}`); if (o.shape.length !== 1) throw new Error(`Input shape should be a vector but received shape ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Target shape should be a vector but received shape ${r.shape}`); const i = Array.from(e.readSync(o.dataId)), a = e.readSync(s.dataId), c = Array.from(e.readSync(r.dataId)), [l, u, d] = _V(a, s.shape, s.dtype, i, c); return [e.makeTensorInfo(u, s.dtype, l), e.makeTensorInfo([d.length], r.dtype, new Int32Array(d))] } const uB = { kernelName: Sf, backendName: "webgl", kernelFunc: lB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function dB(n) {
        const { inputs: t, backend: e } = n, { data: s, indices: o, segmentIds: r } = t; if (s.shape.length < 1) throw new Error("Data should be at least 1 dimensional but received scalar"); if (o.shape.length !== 1) throw new Error(`Indices should be a vector but received shape
              ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Segment ids should be a vector but received shape
              ${r.shape}`); const i = e.readSync(s.dataId), a = e.readSync(o.dataId), c = e.readSync(r.dataId), [l, u] = a1(i, s.shape, s.dtype, a, c, !0); return e.makeTensorInfo(u, s.dtype, l)
    } const hB = { kernelName: kf, backendName: "webgl", kernelFunc: dB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function pB(n) {
        const { inputs: t, backend: e } = n, { data: s, indices: o, segmentIds: r } = t; if (s.shape.length < 1) throw new Error("Data should be at least 1 dimensional but received scalar"); if (o.shape.length !== 1) throw new Error(`Indices should be a vector but received shape
             ${o.shape}`); if (r.shape.length !== 1) throw new Error(`Segment ids should be a vector but received shape
             ${r.shape}`); const i = e.readSync(s.dataId), a = e.readSync(o.dataId), c = e.readSync(r.dataId), [l, u] = a1(i, s.shape, s.dtype, a, c); return e.makeTensorInfo(u, s.dtype, l)
    } const fB = { kernelName: Tf, backendName: "webgl", kernelFunc: pB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function mB(n) { const { inputs: t, backend: e, attrs: s } = n, { sparseIndices: o, sparseValues: r, defaultValue: i } = t, { outputShape: a } = s, { sliceRank: c, numUpdates: l, sliceSize: u, strides: d, outputSize: h } = Ri(r, o, a), p = !1; if (r.dtype === "string") { const b = e.bufferSync(o), x = e.bufferSync(r), I = ms(e.readSync(i.dataId)[0]), y = KV(b, x, a, h, u, l, c, d, I, p); return e.makeTensorInfo(a, y.dtype, y.values) } const f = new sI(l, c, o.shape.length, r.shape.length, d, [h, 1], p), m = e.runWebGLProgram(f, [r, o, i], r.dtype), g = et({ inputs: { x: m }, backend: e, attrs: { shape: a } }); return e.disposeIntermediateTensorInfo(m), g } const gB = { kernelName: Nf, backendName: "webgl", kernelFunc: mB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function bB(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { numOrSizeSplits: r, axis: i } = s, a = It(i, o.shape)[0], c = gh(o, r, a), l = o.shape.length, u = new Array(l).fill(0), d = o.shape.slice(); return c.map(h => { const p = [...d]; p[a] = h; const f = pr({ inputs: { x: o }, backend: e, attrs: { begin: u, size: p } }); return u[a] += h, f }) } const xB = { kernelName: uc, backendName: "webgl", kernelFunc: bB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const oI = "return sqrt(x);", yB = Tt({ opSnippet: oI, packedOpSnippet: oI, cpuKernelImpl: UV }), IB = { kernelName: ai, backendName: "webgl", kernelFunc: yB };/**
 * @license
 * Copyright 2019 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const CB = Tt({ opSnippet: "return x * x;" }), wB = { kernelName: Eu, backendName: "webgl", kernelFunc: CB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const rI = "return (a - b) * (a - b);", vB = we({ opSnippet: rI, packedOpSnippet: rI }), SB = { kernelName: ci, backendName: "webgl", kernelFunc: vB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function kB({ inputs: n, attrs: t, backend: e }) {
        const { x: s } = n, o = Cn + `
    return x > 0.0 ? 1.0 : float(${t.alpha});
  `, r = new Yn(s.shape, o); return e.runWebGLProgram(r, [s], s.dtype)
    } const TB = { kernelName: pi, backendName: "webgl", kernelFunc: kB };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class NB {
        constructor(t, e, s) {
            this.variableNames = ["x"], this.outputShape = s; const o = s.length, r = Xt(s.length), i = Xt(s.length); let a = ""; if (o === 1) a = "coords * strides + begin"; else { let c = 0; a = s.map((l, u) => (c++, s.length === 1 ? `coords * strides[${u}] + begin[${u}]` : `coords[${c - 1}] * strides[${u}] + begin[${u}]`)).join(",") } this.userCode = `
      ${r} begin = ${r}(${t});
      ${r} strides = ${r}(${e});

      void main() {
        ${i} coords = getOutputCoords();
        setOutput(getX(${a}));
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function RB(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { begin: r, end: i, strides: a, beginMask: c, endMask: l, ellipsisMask: u, newAxisMask: d, shrinkAxisMask: h } = s, { finalShapeSparse: p, finalShape: f, isIdentity: m, sliceDim0: g, isSimpleSlice: b, begin: x, end: I, strides: y } = Jd(o.shape, r, i, a, c, l, u, d, h); let C; if (m) C = et({ inputs: { x: o }, backend: e, attrs: { shape: f } }); else if (g || b) { v(o.shape.length >= 1, () => `Input must have rank at least 1, got: ${o.shape.length}`); const k = Ud(x, I, y), S = pr({ inputs: { x: o }, backend: e, attrs: { begin: x, size: k } }); C = et({ inputs: { x: S }, backend: e, attrs: { shape: f } }), e.disposeIntermediateTensorInfo(S) } else if (e.shouldExecuteOnCPU([o])) { const S = e.readSync(o.dataId), T = Ct(o.shape, o.dtype, S), R = YV(p, T, y, x); C = e.makeTensorInfo(f, o.dtype, R.values) } else { const S = new NB(x, y, p); C = e.runWebGLProgram(S, [o], o.dtype) } const w = et({ inputs: { x: C }, backend: e, attrs: { shape: f } }); return e.disposeIntermediateTensorInfo(C), w } const $B = { kernelName: Du, backendName: "webgl", kernelFunc: RB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function GB(n) { const { inputs: t, backend: e, attrs: s } = n, { separator: o, nGramWidths: r, leftPad: i, rightPad: a, padWidth: c, preserveShortSequences: l } = s, { data: u, dataSplits: d } = t, h = e.readSync(u.dataId), p = e.readSync(d.dataId), [f, m] = QV(h, p, o, r, i, a, c, l); return [e.makeTensorInfo([f.length], "string", f), e.makeTensorInfo(d.shape, "int32", m)] } const LB = { kernelName: Rf, backendName: "webgl", kernelFunc: GB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function EB(n) { const { inputs: t, backend: e, attrs: s } = n, { skipEmpty: o } = s, { input: r, delimiter: i } = t; if (r.dtype !== "string") throw new Error("Input must be of datatype string"); if (r.shape.length !== 1) throw new Error(`Input must be a vector, got shape: ${r.shape}`); if (i.shape.length !== 0) throw new Error(`Delimiter must be a scalar, got shape: ${i.shape}`); const a = e.readSync(r.dataId), c = e.readSync(i.dataId)[0], [l, u, d] = JV(a, c, o), h = u.length; return [e.makeTensorInfo([h, 2], "int32", l), e.makeTensorInfo([h], "string", u), e.makeTensorInfo([2], "int32", new Int32Array(d))] } const DB = { kernelName: $f, backendName: "webgl", kernelFunc: EB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function WB(n) { const { inputs: t, backend: e, attrs: s } = n, { numBuckets: o } = s, { input: r } = t; if (r.dtype !== "string") throw new Error("Input must be of datatype string"); if (o <= 0) throw new Error("Number of buckets must be at least 1"); const i = e.readSync(r.dataId), a = jV(i, o); return e.makeTensorInfo(r.shape, "int32", a) } const MB = { kernelName: Gf, backendName: "webgl", kernelFunc: WB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const FB = Tt({ opSnippet: "return tan(x);" }), VB = { kernelName: ui, backendName: "webgl", kernelFunc: FB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const zB = Tt({
        opSnippet: `
  float e2x = exp(-2.0 * abs(x));
  return sign(x) * (1.0 - e2x) / (1.0 + e2x);
`}), XB = { kernelName: di, backendName: "webgl", kernelFunc: zB };/**
 * @license
 * Copyright 2017 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class AB {
        constructor(t, e) {
            this.variableNames = ["A"]; const s = new Array(t.length); for (let i = 0; i < s.length; i++)s[i] = t[i] * e[i]; this.outputShape = s, this.rank = s.length; const o = Xt(this.rank), r = OB(t); this.userCode = `
      void main() {
        ${o} resRC = getOutputCoords();
        setOutput(getA(${r}));
      }
    `}
    } function OB(n) { const t = n.length; if (t > 5) throw Error(`Tile for rank ${t} is not yet supported`); if (t === 1) return `imod(resRC, ${n[0]})`; const e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u"], s = []; for (let o = 0; o < n.length; o++)s.push(`imod(${e[o]}, ${n[o]})`); return s.join() }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function iI(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { reps: r } = s; if (o.dtype === "string" || o.shape.length > 5) { const c = e.readSync(o.dataId), l = o.dtype === "string" ? c.map(h => ms(h)) : c, u = Ct(o.shape, o.dtype, l), d = tz(u, r); return e.makeTensorInfo(d.shape, d.dtype, d.values) } const i = new AB(o.shape, r); return e.runWebGLProgram(i, [o], o.dtype) } const PB = { kernelName: hi, backendName: "webgl", kernelFunc: iI }; class KB {
        constructor(t) {
            this.variableNames = ["x", "indices"], this.customUniforms = [{ name: "n", type: "int" }, { name: "firstPass", type: "int" }, { name: "negativeInf", type: "float" }, { name: "dir", type: "int" }, { name: "inc", type: "int" }], this.outputShape = t, this.userCode = `
       void main() {
         ivec2 coords = getOutputCoords();
         int batch = coords[0];
         int elemIdx = coords[1];

         // We compare elements pair-wise within a group of size 2 * inc.
         // The comparing rule for each group alternates between ascending
         // and descending. Within each group, we compare each pair at
         // positions i and i+inc. To decide whether an element at position i
         // is x0 or x1, we mod it by 2 * inc, if the result is smaller than
         // inc, it is in the first half of the group, we denote it as x0,
         // otherwise we denote it as x1.
         // For example, as shown in the Bitonic top K paper referenced above,
         // Figure5(a) shows that element[1] is in the
         // second half of the group when group size is 2, but it is in the
         // first half of the group when group size is 4.

         bool isFirstInPair = imod(elemIdx, 2 * inc) < inc;
         int i = isFirstInPair ? elemIdx : elemIdx - inc;

         int i0 = firstPass == 1 ? i : int(getIndices(batch, i));
         int i1 = firstPass == 1 ? i + inc : int(getIndices(batch, i + inc));
         float x0 = i0 < n ? getX(batch, i0) : negativeInf;
         float x1 = i1 < n ? getX(batch, i1) : negativeInf;

         // Denotes which direction indices are in (ascending or descending).
         bool reverse = imod(elemIdx, 2 * dir) >= dir;
         bool isGreater = x0 > x1 || (x0 == x1 && i1 > i0);
         if (reverse == isGreater) { // Elements in opposite order of direction
           int iTemp = i0;
           i0 = i1;
           i1 = iTemp;
         }
         if (isFirstInPair) {
            setOutput(float(i0));
         } else {
            setOutput(float(i1));
         }
       }
     `}
    } class ZB {
        constructor(t) {
            this.variableNames = ["x", "indices"], this.customUniforms = [{ name: "n", type: "int" }, { name: "firstPass", type: "int" }, { name: "k", type: "int" }], this.outputShape = t, this.userCode = `
    void main() {
         // Takes max of indices (0, k), (1, k + 1), (2, k + 2) ...
         ivec2 coords = getOutputCoords();
         int batch = coords[0];
         int elemIdx = coords[1];

         // The output size is half of the previous size.
         // If the previous sequence is | | | | _ _ _ _  | | | |  _ _ _ _ (k=4),
         // we only need to output the indices at positions |, the indices at
         // positions _ can be thrown away, see Figure5(b) After Phase 2
         // (Merge phase) in the Bitonic Top K paper referenced above.
         // For example, the paper shows we only need to output the orange bars.
         // The output sequence should look like this | | | | | | | |.
         // Because the sequence is halved, to map the output index back
         // to the previous sequence to find the corresponding value,
         // we need to double the index. When we double the index,
         // we basically interpolate a position, so 2i looks like
         // | _ | _ | _ | _ | _ | _ | _. We move the | to the first k position
         // of each 2k positions by - elemIdx % k. E.g. for output at
         // index 4,5,6,7, we want to get the corresponding element at
         // original index 8,9,10,11, for output at index 8,9,10,11,
         // we want to get the corresponding element at original index
         // 16,17,18,19, so on and so forth.

         int i = elemIdx < k ? elemIdx : (elemIdx * 2 - imod(elemIdx, k));
         int i0 = firstPass == 1 ? i : int(getIndices(batch, i));
         int i1 = firstPass == 1 ? i + k : int(getIndices(batch, i + k));

         float x0 = getX(batch, i0);
         float x1 = i1 < n ? getX(batch, i1) : x0;

         setOutput(x0 >= x1 ? float(i0) : float(i1));
       }
     `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function vo(n, t) { t !== null && n.disposeIntermediateTensorInfo(t) } function aI(n) { let t = 1; for (; t < n;)t *= 2; return t } function BB(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o } = t, { k: r, sorted: i } = s, a = A().getNumber("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD"), c = A().getNumber("TOPK_K_CPU_HANDOFF_THRESHOLD"), l = o.shape, u = l[l.length - 1]; if (e.shouldExecuteOnCPU([o]) || u < a || r > c) { const R = e.readSync(o.dataId), [G, F] = ez(R, l, o.dtype, r, i); return [e.makeTensorInfo(G.shape, G.dtype, G.values), e.makeTensorInfo(F.shape, F.dtype, F.values)] } if (r === 0) return l[l.length - 1] = 0, [e.makeTensorInfo(l, o.dtype, []), e.makeTensorInfo(l, "int32", [])]; if (u === 1) return [o, ca({ attrs: { shape: l, dtype: "int32", value: 0 }, backend: e })]; const d = e.texData.get(o.dataId), h = d !== null && d.isPacked, p = h ? e.unpackTensor(o) : o, m = Z(l) / u, g = et({ inputs: { x: p }, attrs: { shape: [m, u] }, backend: e }); h && vo(e, p); const b = aI(r), x = aI(u); let I = null; const y = () => I === null ? [g, g] : [g, I], C = (R, G, F) => { const V = y(), z = new KB(F), O = [[u], [I === null ? 1 : 0], [Number.NEGATIVE_INFINITY], [R], [G]], B = I; I = e.runWebGLProgram(z, V, "int32", O), vo(e, B) }; for (let R = 1; R < b; R *= 2) { const G = R * 2; for (let F = R; F >= 1; F /= 2)C(G, F, [m, x]) } for (let R = x; R > b; R /= 2) { const G = y(), F = new ZB([m, R / 2]), z = [[u], [I === null ? 1 : 0], [b]], X = I; I = e.runWebGLProgram(F, G, "int32", z), vo(e, X); const O = b / 2, B = O * 2; for (let K = O; K >= 1; K /= 2)C(B, K, I.shape) } let w = I; I = pr({ inputs: { x: I }, backend: e, attrs: { begin: 0, size: [m, r] } }), vo(e, w); let k = U1({ inputs: { x: g, indices: I }, backend: e, attrs: { axis: 1, batchDims: 1 } }); vo(e, g); const S = l.slice(0, -1); S.push(r), w = I, I = et({ inputs: { x: I }, attrs: { shape: S }, backend: e }), vo(e, w); const T = k; return k = et({ inputs: { x: k }, attrs: { shape: S }, backend: e }), vo(e, T), [k, I] } const HB = { kernelName: Wu, backendName: "webgl", kernelFunc: BB };/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class _B {
        constructor(t, e, s, o, r, i) {
            this.variableNames = ["Image", "Transforms"], this.outputShape = i; const a = s === "nearest" ? 1 : 2; let c; switch (o) { case "constant": c = 1; break; case "reflect": c = 2; break; case "wrap": c = 3; break; case "nearest": c = 4; break; default: c = 1; break }this.userCode = `
            float mapCoord(float outCoord, float len) {
              float inCoord = outCoord;
              if(${c} == 2) {
                if (inCoord < 0.0) {
                  if (len <= 1.0) {
                    inCoord = 0.0;
                  } else {
                    float sz2 = 2.0 * len;
                    if (inCoord < sz2) {
                      inCoord = sz2 * float(int(float(-inCoord / sz2))) +
                      inCoord;
                    }
                    inCoord = inCoord < -len ? inCoord + sz2 : -inCoord - 1.0;
                  }
                } else if (inCoord > len - 1.0) {
                  if (len <= 1.0) {
                    inCoord = 0.0;
                  } else {
                    float sz2 = 2.0 * len;
                    inCoord -= sz2 * float(int(float(inCoord / sz2)));
                    if (inCoord >= len) {
                      inCoord = sz2 - inCoord - 1.0;
                    }
                  }
                }
                return clamp(inCoord, 0.0, len - 1.0);
              } else if (${c} == 3) {
                if (inCoord < 0.0) {
                  if (len <= 1.0) {
                    inCoord = 0.0;
                  } else {
                    float sz = len - 1.0;
                    inCoord += len * (float(int(float(-inCoord / sz))) + 1.0);
                  }
                } else if (inCoord > len - 1.0) {
                  if (len <= 1.0) {
                    inCoord = 0.0;
                  } else {
                    float sz = len - 1.0;
                    inCoord -= len * float(int(float(inCoord / sz)));
                  }
                }
                return clamp(inCoord, 0.0, len - 1.0);
              } else if (${c} == 4) {
                return clamp(outCoord, 0.0, len - 1.0);
              } else {
                return outCoord;
              }
            }

            float readWithFillValue(int batch, int coordY, int coordX,
              int channel) {
              float outputValue;
              if (0 <= coordY && coordY < ${t} && 0 <= coordX && coordX < ${e}) {
                  outputValue = getImage(batch, coordY, coordX, channel);
              } else {
                outputValue = float(${r});
              }
              return outputValue;
            }

            void main() {
              ivec4 coords = getOutputCoords();
              float outputValue;
              int batch = coords[0];
              int x = coords[2];
              int y = coords[1];
              int channel = coords[3];
              float xf = float(x);
              float yf = float(y);
              float a1 = getTransforms(batch, 0);
              float a2 = getTransforms(batch, 1);
              float a3 = getTransforms(batch, 2);
              float b1 = getTransforms(batch, 3);
              float b2 = getTransforms(batch, 4);
              float b3 = getTransforms(batch, 5);
              float c1 = getTransforms(batch, 6);
              float c2 = getTransforms(batch, 7);
              float projection = c1 * xf + c2 * yf + 1.0;
              if (projection == 0.0) {
                outputValue = float(${r});
              } else {
                float inX = (a1 * xf + a2 * yf + a3) / projection;
                float inY = (b1 * xf + b2 * yf + b3) / projection;
                float mapX = mapCoord(inX, float(${e}));
                float mapY = mapCoord(inY, float(${t}));

                if (${a} == 1) {
                  int coordY = int(round(mapY));
                  int coordX = int(round(mapX));
                  outputValue = readWithFillValue(batch, coordY, coordX,
                    channel);
                } else {
                  float yFloor = floor(mapY);
                  float xFloor = floor(mapX);
                  float yCeil = yFloor + 1.0;
                  float xCeil = xFloor + 1.0;
                  float valueYFloor = (xCeil - mapX) *
                  readWithFillValue(batch, int(yFloor), int(xFloor), channel) +
                  (mapX - xFloor) *
                  readWithFillValue(batch, int(yFloor), int(xCeil), channel);
                  float valueYCeil = (xCeil - mapX) *
                  readWithFillValue(batch, int(yCeil), int(xFloor), channel) +
                  (mapX - xFloor) *
                  readWithFillValue(batch, int(yCeil), int(xCeil), channel);
                  outputValue = (yCeil - mapY) * valueYFloor +
                  (mapY - yFloor) * valueYCeil;
                }
              }
              setOutput(outputValue);
            }
        `}
    }/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function UB(n) { const { inputs: t, backend: e, attrs: s } = n, { image: o, transforms: r } = t, { interpolation: i, fillMode: a, fillValue: c, outputShape: l } = s, [u, d, h, p] = o.shape, [f, m] = l ?? [d, h], g = [u, f, m, p], b = new _B(d, h, i, a, c, g); return e.runWebGLProgram(b, [o, r], "float32") } const YB = { kernelName: Mu, backendName: "webgl", kernelFunc: UB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function QB(n) { const { inputs: t, attrs: e, backend: s } = n, { axis: o } = e, { x: r } = t; qi(r, "unique"), console.warn("WARNING: ", "UI might be locked temporarily as data is being downloaded"); const i = s.readSync(r.dataId), { outputValues: a, outputShape: c, indices: l } = nz(i, o, r.shape, r.dtype); return [s.makeTensorInfo(c, r.dtype, a), s.makeTensorInfo([l.length], "int32", l)] } const JB = { kernelName: Fu, backendName: "webgl", kernelFunc: QB };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function jB(n) { const { inputs: t, backend: e, attrs: s } = n, { value: o } = t; let { axis: r } = s; r < 0 && (r += o.shape.length); const i = o, a = i.shape.length, c = o.shape[r], l = new Array(a - 1); let u = 0; for (let m = 0; m < a; m++)m !== r && (l[u++] = i.shape[m]); const d = [], h = new Array(a).fill(0), p = i.shape.slice(); p[r] = 1; const f = new Array(c); for (let m = 0; m < f.length; m++) { h[r] = m; const g = pr({ inputs: { x: i }, backend: e, attrs: { begin: h, size: p } }), b = et({ inputs: { x: g }, backend: e, attrs: { shape: l } }); f[m] = b, d.push(g) } return d.forEach(m => e.disposeIntermediateTensorInfo(m)), f } const qB = { kernelName: hc, backendName: "webgl", kernelFunc: jB };/**
 * @license
 * Copyright 2018 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */class tH {
        constructor(t, e) {
            this.variableNames = ["x", "segmentIds"]; const s = t.windowSize, o = t.batchSize, r = t.inSize, i = t.numSegments, a = i * Math.ceil(r / s); this.outputShape = [o, a]; const c = "0.0", l = "sumValue", u = Math.floor(s / 4) * 4, d = s % 4, h = `
        sumValue += dot(values, segFilter);
    `; let p = ""; r % s > 0 && (p = `
        if (inIdx < 0 || inIdx >= ${r}) {
          return initializationValue;
        }
      `); let f = ""; r % s > 0 && (f = `
        if (inIdx < 0 || inIdx >= ${r}) {
          return -1.0;
        }
      `), this.userCode = `
      const float initializationValue = ${c};

      float getValue(int batch, int inIdx) {
        ${p}
        return getX(batch, inIdx);
      }

      float getSegmentIdAtIndex(int inIdx) {
        ${f}
        return getSegmentIds(inIdx);
      }

      void main() {
        ivec2 coords = getOutputCoords();
        int batch = coords[0];
        int outIdx = coords[1];
        int inOffset = int(floor(float(outIdx) / float(
          ${i})) * float(${s}));
        int currentSeg = int(mod(float(outIdx), float(${i})));

        float sumValue = 0.0;

        for (int i = 0; i < ${u}; i += 4) {
          int inIdx = inOffset + i;
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2),
            getValue(batch, inIdx + 3)
          );

          vec4 segFilter = vec4(
            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0
          );

          ${h}
        }

        int inIdx = inOffset + ${u};
        if (${d === 1}) {
          vec4 values = vec4(
            getValue(batch, inIdx),
            initializationValue,
            initializationValue,
            initializationValue
          );

          int inIdxSeg = int(getSegmentIdAtIndex(inIdx));

          vec4 segFilter = vec4(
            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
            0,
            0,
            0
          );

          ${h}
        } else if (${d === 2}) {
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            initializationValue,
            initializationValue
          );

          vec4 segFilter = vec4(
            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
              0,
              0
          );

          ${h}
        } else if (${d === 3}) {
          vec4 values = vec4(
            getValue(batch, inIdx),
            getValue(batch, inIdx + 1),
            getValue(batch, inIdx + 2),
            initializationValue
          );

          vec4 segFilter = vec4(
            int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,
            int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,
            0
          );

          ${h}
        }
        setOutput(${l});
      }
    `}
    }/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */function eH(n) { const { inputs: t, backend: e, attrs: s } = n, { x: o, segmentIds: r } = t, { numSegments: i } = s, a = o.shape.length, c = []; let l = 0; const u = Yt([l], a); let d = o; u != null && (d = We({ inputs: { x: o }, backend: e, attrs: { perm: u } }), c.push(d), l = te(1, a)[0]); const h = Ag(d.shape, l, i), p = Z([d.shape[l]]), f = et({ inputs: { x: d }, backend: e, attrs: { shape: [-1, p] } }); c.push(f); const m = Yu(o.dtype), g = (y, C, w, k, S) => { const T = y.shape[0], R = y.shape[1], G = Xg(R, S), F = { windowSize: G, inSize: R, batchSize: T, numSegments: S }, V = new tH(F, C), z = e.compileAndRun(V, [y, w], k); if (c.push(z), z.shape[1] === S) return z; const X = nI({ backend: e, attrs: { start: 0, stop: S, step: 1, dtype: "float32" } }), O = iI({ inputs: { x: X }, backend: e, attrs: { reps: [R / G] } }); return c.push(X), c.push(O), g(z, C, O, k, S) }, b = g(f, "unsortedSegmentSum", r, m, i), x = et({ inputs: { x: b }, backend: e, attrs: { shape: h } }); let I = x; if (u != null) { c.push(x); const y = ys(u); I = We({ inputs: { x: I }, backend: e, attrs: { perm: y } }) } return c.forEach(y => e.disposeIntermediateTensorInfo(y)), I } const nH = { kernelName: pc, backendName: "webgl", kernelFunc: eH };/**
 * @license
 * Copyright 2020 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */const sH = [_z, Yz, jz, eX, sX, iX, cX, uX, fX, gX, yX, wX, kX, $X, EX, WX, FX, AX, PX, ZX, _X, qX, eA, sA, cA, uA, fA, Gz, bA, wA, TA, EA, WA, FA, zA, AA, KA, BA, _A, YA, JA, qA, nO, oO, cO, uO, pO, gO, xO, IO, vO, kO, RO, GO, LO, DO, MO, VO, XO, OO, KO, HO, YO, JO, tP, sP, rP, aP, $z, lP, IA, dP, pP, mP, Ez, bP, yP, CP, SP, NP, $P, LP, DP, FP, zP, AP, ZP, HP, UP, jP, tK, nK, oK, iK, uK, pK, bK, vK, Mz, NK, GK, DK, FK, oA, zK, AK, PK, BK, YK, Wz, JK, qK, eZ, sZ, oZ, rA, yK, iZ, lZ, hZ, Vz, gZ, yZ, vZ, TZ, GZ, EZ, WZ, FZ, zZ, OZ, ZZ, _Z, QZ, jZ, eB, sB, jX, CK, rB, iB, cB, uB, hB, fB, gB, xB, IB, wB, SB, TB, $B, LB, DB, MB, IK, Zz, VB, XB, PB, HB, YB, Bz, JB, qB, nH, XK]; for (const n of sH) Je(n); const cI = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NsYXNzIFd0e2NvbnN0cnVjdG9yKG49W10sZT1RdCl7aWYodGhpcy5kYXRhPW4sdGhpcy5sZW5ndGg9dGhpcy5kYXRhLmxlbmd0aCx0aGlzLm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hcmdldEluZGV4ZXM7bGV0IHQ9LTEscz1udWxsLHI9bnVsbDtmb3IobGV0IGY9MDtmPGUubGVuZ3RoO2YrKyl7Y29uc3QgZz1lW2ZdLHtrZXlmcmFtZUluZGV4OmEsc2NyZWVuQ29vcmRzOmosd29ybGRDb29yZHM6dyxkZWJ1Z0V4dHJhOnl9PUd0Lm1hdGNoRGV0ZWN0aW9uKEt0W2ddLG4uZmVhdHVyZVBvaW50cyk7aWYocj15LGEhPT0tMSl7Y29uc3QgbT1TdC5lc3RpbWF0ZSh7c2NyZWVuQ29vcmRzOmosd29ybGRDb29yZHM6d30pO20mJih0PWcscz1tKTticmVha319cG9zdE1lc3NhZ2Uoe3R5cGU6Im1hdGNoRG9uZSIsdGFyZ2V0SW5kZXg6dCxtb2RlbFZpZXdUcmFuc2Zvcm06cyxkZWJ1Z0V4dHJhOnJ9KTticmVhaztjYXNlInRyYWNrVXBkYXRlIjpjb25zdHttb2RlbFZpZXdUcmFuc2Zvcm06aSx3b3JsZENvb3JkczpoLHNjcmVlbkNvb3JkczpsfT1uLHU9U3QucmVmaW5lRXN0aW1hdGUoe2luaXRpYWxNb2RlbFZpZXdUcmFuc2Zvcm06aSx3b3JsZENvb3JkczpoLHNjcmVlbkNvb3JkczpsfSk7cG9zdE1lc3NhZ2Uoe3R5cGU6InRyYWNrVXBkYXRlRG9uZSIsbW9kZWxWaWV3VHJhbnNmb3JtOnV9KTticmVhaztjYXNlImRpc3Bvc2UiOmNsb3NlKCk7YnJlYWs7ZGVmYXVsdDp0aHJvdyBuZXcgRXJyb3IoYEludmFsaWQgbWVzc2FnZSB0eXBlICcke24udHlwZX0nYCl9fX0pKCk7Cg==", lI = typeof window < "u" && window.Blob && new Blob([atob(cI)], { type: "text/javascript;charset=utf-8" }); function oH() { let n; try { if (n = lI && (window.URL || window.webkitURL).createObjectURL(lI), !n) throw ""; return new Worker(n) } catch { return new Worker("data:application/javascript;base64," + cI) } finally { n && (window.URL || window.webkitURL).revokeObjectURL(n) } } const rH = (n, t) => [[n[0][0] * t[0][0] + n[0][2] * t[2][0], n[0][0] * t[0][1] + n[0][2] * t[2][1], n[0][0] * t[0][2] + n[0][2] * t[2][2], n[0][0] * t[0][3] + n[0][2] * t[2][3]], [n[1][1] * t[1][0] + n[1][2] * t[2][0], n[1][1] * t[1][1] + n[1][2] * t[2][1], n[1][1] * t[1][2] + n[1][2] * t[2][2], n[1][1] * t[1][3] + n[1][2] * t[2][3]], [t[2][0], t[2][1], t[2][2], t[2][3]]], iH = (n, t, e, s) => { const o = n[0][0] * t + n[0][1] * e + n[0][3], r = n[1][0] * t + n[1][1] * e + n[1][3], i = n[2][0] * t + n[2][1] * e + n[2][3]; return { x: o, y: r, z: i } }, aH = (n, t, e, s) => { const { x: o, y: r, z: i } = iH(n, t, e); return { x: o / i, y: r / i } }, cH = 6, lH = 1, uH = 10, dH = 1, hH = .8, pH = 1, Qn = 1e3; class fH {
        constructor(t, e, s, o, r, i = !1) { this.markerDimensions = t, this.trackingDataList = e, this.projectionTransform = s, this.debugMode = i, this.trackingKeyframeList = []; for (let c = 0; c < e.length; c++)this.trackingKeyframeList.push(e[c][pH]); let a = 0; for (let c = 0; c < this.trackingKeyframeList.length; c++)a = Math.max(a, this.trackingKeyframeList[c].points.length); this.featurePointsListT = [], this.imagePixelsListT = [], this.imagePropertiesListT = []; for (let c = 0; c < this.trackingKeyframeList.length; c++) { const { featurePoints: l, imagePixels: u, imageProperties: d } = this._prebuild(this.trackingKeyframeList[c], a); this.featurePointsListT[c] = l, this.imagePixelsListT[c] = u, this.imagePropertiesListT[c] = d } this.kernelCaches = {} } dummyRun(t) { let e = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]; for (let s = 0; s < this.featurePointsListT.length; s++)this.track(t, e, s) } track(t, e, s) { let o = {}; const r = rH(this.projectionTransform, e), i = this._buildAdjustedModelViewTransform(r); this.markerDimensions[s][0], this.markerDimensions[s][1], this.trackingKeyframeList[s].width, this.trackingKeyframeList[s].height; const a = this.featurePointsListT[s], c = this.imagePixelsListT[s], l = this.imagePropertiesListT[s], u = this._computeProjection(i, t, s), { matchingPointsT: d, simT: h } = this._computeMatching(a, c, l, u), p = d.arraySync(), f = h.arraySync(), m = this.trackingKeyframeList[s], g = [], b = [], x = []; for (let I = 0; I < p.length; I++)if (f[I] > hH && I < m.points.length) { x.push(I); const y = aH(r, p[I][0], p[I][1]); b.push(y), g.push({ x: m.points[I].x / m.scale, y: m.points[I].y / m.scale, z: 0 }) } return this.debugMode && (o = { projectedImage: u.arraySync(), matchingPoints: d.arraySync(), goodTrack: x, trackedPoints: b }), i.dispose(), u.dispose(), d.dispose(), h.dispose(), { worldCoords: g, screenCoords: b, debugExtra: o } } _computeMatching(t, e, s, o) {
            const r = cH, i = r * 2 + 1, c = uH * lH, l = dH, u = c * 2 + 1, d = o.shape[0], h = o.shape[1], p = t.shape[0]; if (!this.kernelCaches.computeMatching) {
                const f = {
                    variableNames: ["features", "markerPixels", "markerProperties", "targetPixels"], outputShape: [p, u * u], userCode: `
	  void main() {
	    ivec2 coords = getOutputCoords();

	    int featureIndex = coords[0];
	    int searchOffsetIndex = coords[1];

	    int markerWidth = int(getMarkerProperties(0));
	    int markerHeight = int(getMarkerProperties(1));
	    float markerScale = getMarkerProperties(2);

	    int searchOffsetX = imod(searchOffsetIndex, ${u}) * ${l};
	    int searchOffsetY = searchOffsetIndex / ${u} * ${l};

	    int sCenterX = int(getFeatures(featureIndex, 0) * markerScale);
	    int sCenterY = int(getFeatures(featureIndex, 1) * markerScale);

	    int sx = sCenterX + searchOffsetX - ${c};
	    int sy = sCenterY + searchOffsetY - ${c};

	    if (sx < ${r} || sx >= (${h} - ${r}) || sy < ${r} || sy >= (${d} - ${r})) {
	      setOutput(-2.);
	    } 
	    else {
	      float sumPoint = 0.;
	      float sumPointSquare = 0.;
	      float sumTemplate = 0.;
	      float sumTemplateSquare = 0.;
	      float sumPointTemplate = 0.;

	      for (int templateOffsetY = 0; templateOffsetY < ${i}; templateOffsetY++) {
		for (int templateOffsetX = 0; templateOffsetX < ${i}; templateOffsetX++) {
		  int fx2 = sCenterX + templateOffsetX - ${r};
		  int fy2 = sCenterY + templateOffsetY - ${r};

		  int sx2 = sx + templateOffsetX - ${r};
		  int sy2 = sy + templateOffsetY - ${r};

		  int markerPixelIndex = fy2 * markerWidth + fx2;
		  float markerPixel = getMarkerPixels(markerPixelIndex);
		  float targetPixel = getTargetPixels(sy2, sx2);

		  sumTemplate += markerPixel;
		  sumTemplateSquare += markerPixel * markerPixel;
		  sumPoint += targetPixel;
		  sumPointSquare += targetPixel * targetPixel;
		  sumPointTemplate += targetPixel * markerPixel;
		}
	      }

	      // Normalized cross-correlation
	      // !important divide first avoid overflow (e.g. sumPoint / count * sumPoint)
	      float count = float(${i} * ${i});
	      float pointVariance = sqrt(sumPointSquare - sumPoint / count * sumPoint);
	      float templateVariance = sqrt(sumTemplateSquare - sumTemplate / count * sumTemplate);

	      if (pointVariance < 0.0000001) {
		setOutput(-3.);
	      } else if (templateVariance < 0.0000001) {
		//setOutput(sumTemplate);
		setOutput(-4.);
	      } else {
		sumPointTemplate -= sumPoint / count * sumTemplate;
		float sim = sumPointTemplate / pointVariance / templateVariance;  
		setOutput(sim);
	      }
	    }
	  }
	`}, m = {
                    variableNames: ["featurePoints", "markerProperties", "maxIndex"], outputShape: [p, 2], userCode: `
	  void main() {
	    ivec2 coords = getOutputCoords();

	    float markerScale = getMarkerProperties(2);

	    int featureIndex = coords[0];

	    int maxIndex = int(getMaxIndex(featureIndex));
	    int searchLocationIndex = maxIndex / ${u * u};
	    int searchOffsetIndex = imod(maxIndex, ${u * u});

	    if (coords[1] == 0) {
	      int searchOffsetX = imod(searchOffsetIndex, ${u}) * ${l};
	      setOutput(getFeaturePoints(featureIndex, 0) + float(searchOffsetX - ${c}) / markerScale);
	    }
	    else if (coords[1] == 1) {
	      int searchOffsetY = searchOffsetIndex / ${u} * ${l};
	      setOutput(getFeaturePoints(featureIndex, 1) + float(searchOffsetY - ${c}) / markerScale);
	    }
	  }
	`}, g = {
                    variableNames: ["sims", "maxIndex"], outputShape: [p], userCode: `
	  void main() {
	    int featureIndex = getOutputCoords();
	    int maxIndex = int(getMaxIndex(featureIndex));
	    setOutput(getSims(featureIndex, maxIndex));
	  }
	`}; this.kernelCaches.computeMatching = [f, m, g]
            } return M(() => { const f = this.kernelCaches.computeMatching, m = this._compileAndRun(f[0], [t, e, s, o]), g = m.argMax(1), b = this._compileAndRun(f[1], [t, s, g]), x = this._compileAndRun(f[2], [m, g]); return { matchingPointsT: b, simT: x } })
        } _computeProjection(t, e, s) {
            const o = this.trackingKeyframeList[s].width, r = this.trackingKeyframeList[s].height, i = this.trackingKeyframeList[s].scale, a = o + "-" + r + "-" + i; if (this.kernelCaches.computeProjection || (this.kernelCaches.computeProjection = {}), !this.kernelCaches.computeProjection[a]) {
                const c = {
                    variableNames: ["M", "pixel"], outputShape: [r, o], userCode: `
	  void main() {
	      ivec2 coords = getOutputCoords();

	      float m00 = getM(0, 0) * ${Qn}.;
	      float m01 = getM(0, 1) * ${Qn}.;
	      float m03 = getM(0, 3) * ${Qn}.;
	      float m10 = getM(1, 0) * ${Qn}.;
	      float m11 = getM(1, 1) * ${Qn}.;
	      float m13 = getM(1, 3) * ${Qn}.;
	      float m20 = getM(2, 0) * ${Qn}.;
	      float m21 = getM(2, 1) * ${Qn}.;
	      float m23 = getM(2, 3) * ${Qn}.;

	      float y = float(coords[0]) / float(${i});
	      float x = float(coords[1]) / float(${i});
	      float uz = (x * m20) + (y * m21) + m23;
	      float oneOverUz = 1. / uz;

	      float ux = (x * m00) + (y * m01) + m03;
	      float uy = (x * m10) + (y * m11) + m13;

	      ux = floor(ux * oneOverUz + 0.5);
	      uy = floor(uy * oneOverUz + 0.5);
	      setOutput(getPixel(int(uy), int(ux)));
	    }
	`}; this.kernelCaches.computeProjection[a] = c
            } return M(() => { const c = this.kernelCaches.computeProjection[a]; return this._compileAndRun(c, [t, e]) })
        } _buildAdjustedModelViewTransform(t) { return M(() => { let e = []; for (let o = 0; o < t.length; o++) { e.push([]); for (let r = 0; r < t[o].length; r++)e[o].push(t[o][r] / Qn) } return qe(e, [3, 4]) }) } _prebuild(t, e) { return M(() => { const s = t.scale, o = []; for (let c = 0; c < e; c++)c < t.points.length ? o.push([t.points[c].x / s, t.points[c].y / s]) : o.push([-1, -1]); const r = qe(t.data, [t.width * t.height]), i = qe([t.width, t.height, t.scale], [3]); return { featurePoints: qe(o, [o.length, 2], "float32"), imagePixels: r, imageProperties: i } }) } _compileAndRun(t, e) { const s = bs().compileAndRun(t, e); return Ft().makeTensorFromDataId(s.dataId, s.shape, s.dtype) }
    } const Dl = [{ sigma: .55, points: [[-1, 0], [-.5, -.866025], [.5, -.866025], [1, -0], [.5, .866025], [-.5, .866025]] }, { sigma: .475, points: [[0, .930969], [-.806243, .465485], [-.806243, -.465485], [-0, -.930969], [.806243, -.465485], [.806243, .465485]] }, { sigma: .4, points: [[.847306, -0], [.423653, .733789], [-.423653, .733789], [-.847306, 0], [-.423653, -.733789], [.423653, -.733789]] }, { sigma: .325, points: [[-0, -.741094], [.641806, -.370547], [.641806, .370547], [0, .741094], [-.641806, .370547], [-.641806, -.370547]] }, { sigma: .25, points: [[-.595502, 0], [-.297751, -.51572], [.297751, -.51572], [.595502, -0], [.297751, .51572], [-.297751, .51572]] }, { sigma: .175, points: [[0, .362783], [-.314179, .181391], [-.314179, -.181391], [-0, -.362783], [.314179, -.181391], [.314179, .181391]] }, { sigma: .1, points: [[0, 0]] }], So = []; for (let n = 0; n < Dl.length; n++) { const t = Dl[n].sigma; for (let e = 0; e < Dl[n].points.length; e++) { const s = Dl[n].points[e]; So.push([t, s[0], s[1]]) } } const Ep = {}; function mH(n) {
        const t = n.shape[1], e = n.shape[0], s = "w" + t + "h" + e; if (!Ep.hasOwnProperty(s)) {
            const o = {
                variableNames: ["p"], outputShape: [e, t], userCode: `
        void main() {
          ivec2 coords = getOutputCoords();

          float sum = getP(coords[0], coords[1]-2);
          sum += getP(coords[0], coords[1]-1) * 4.;
          sum += getP(coords[0], coords[1]) * 6.;
          sum += getP(coords[0], coords[1]+1) * 4.;
          sum += getP(coords[0], coords[1]+2);
          setOutput(sum);
        }
      `}, r = {
                variableNames: ["p"], outputShape: [e, t], userCode: `
        void main() {
          ivec2 coords = getOutputCoords();

          float sum = getP(coords[0]-2, coords[1]);
          sum += getP(coords[0]-1, coords[1]) * 4.;
          sum += getP(coords[0], coords[1]) * 6.;
          sum += getP(coords[0]+1, coords[1]) * 4.;
          sum += getP(coords[0]+2, coords[1]);
          sum /= 256.;
          setOutput(sum);
        }
      `}; Ep[s] = [o, r]
        } return Ep[s]
    } const gH = { kernelName: "BinomialFilter", backendName: "webgl", kernelFunc: n => { const t = n.inputs.image, e = n.backend, [s, o] = mH(t), r = e.runWebGLProgram(s, [t], t.dtype), i = e.runWebGLProgram(o, [r], t.dtype); return e.disposeIntermediateTensorInfo(r), i } }, Wl = 7, uI = 3, bH = uI * uI, Dp = 4, xH = (Dp + 1) * (Dp + 1) / Dp, Wp = {}; function yH(n) {
        const t = n.shape[1], e = n.shape[0], s = "w" + t + "h" + e; if (!Wp.hasOwnProperty(s)) {
            const o = {
                variableNames: ["image0", "image1", "image2"], outputShape: [e, t], userCode: `
        void main() {
          ivec2 coords = getOutputCoords();
    
          int y = coords[0];
          int x = coords[1];
    
          float value = getImage1(y, x);
    
          // Step 1: find local maxima/minima
          if (value * value < ${bH}.) {
            setOutput(0.);
            return;
          }
          if (y < ${Wl} || y > ${e - 1 - Wl}) {
            setOutput(0.);
            return;
          }
          if (x < ${Wl} || x > ${t - 1 - Wl}) {
            setOutput(0.);
            return;
          }
    
          bool isMax = true;
          bool isMin = true;
          for (int dy = -1; dy <= 1; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
              float value0 = getImage0(y+dy, x+dx);
              float value1 = getImage1(y+dy, x+dx);
              float value2 = getImage2(y+dy, x+dx);
    
        if (value < value0 || value < value1 || value < value2) {
          isMax = false;
        }
        if (value > value0 || value > value1 || value > value2) {
          isMin = false;
        }
            }
          }
    
          if (!isMax && !isMin) {
            setOutput(0.);
            return;
          }
    
          // compute edge score and reject based on threshold
          float dxx = getImage1(y, x+1) + getImage1(y, x-1) - 2. * getImage1(y, x);
          float dyy = getImage1(y+1, x) + getImage1(y-1, x) - 2. * getImage1(y, x);
          float dxy = 0.25 * (getImage1(y-1,x-1) + getImage1(y+1,x+1) - getImage1(y-1,x+1) - getImage1(y+1,x-1));
    
          float det = (dxx * dyy) - (dxy * dxy);
    
          if (abs(det) < 0.0001) { // determinant undefined. no solution
            setOutput(0.);
            return;
          }
    
          float edgeScore = (dxx + dyy) * (dxx + dyy) / det;
    
          if (abs(edgeScore) >= ${xH} ) {
            setOutput(0.);
            return;
          }
          setOutput(getImage1(y,x));
        }
      `}; Wp[s] = o
        } return Wp[s]
    } const IH = { kernelName: "BuildExtremas", backendName: "webgl", kernelFunc: n => { let { image0: t, image1: e, image2: s } = n.inputs; const o = n.backend, r = yH(e); return t = Ft().runKernel("DownsampleBilinear", { image: t }), s = Ft().runKernel("UpsampleBilinear", { image: s, targetImage: e }), o.runWebGLProgram(r, [t, e, s], e.dtype) } }, la = 36, Mp = {}; function CH(n) {
        const t = n.shape[0]; if (!Mp.hasOwnProperty(t)) {
            const e = {
                variableNames: ["histogram"], outputShape: [n.shape[0]], userCode: `
            void main() {
                int featureIndex = getOutputCoords();

                int maxIndex = 0;
                for (int i = 1; i < ${la}; i++) {
                    if (getHistogram(featureIndex, i) > getHistogram(featureIndex, maxIndex)) {
                        maxIndex = i;
                    }
                }

                int prev = imod(maxIndex - 1 + ${la}, ${la});
                int next = imod(maxIndex + 1, ${la});

                /**
                 * Fit a quatratic to 3 points. The system of equations is:
                 *
                 * y0 = A*x0^2 + B*x0 + C
                 * y1 = A*x1^2 + B*x1 + C
                 * y2 = A*x2^2 + B*x2 + C
                 *
                 * This system of equations is solved for A,B,C.
                 */
                float p10 = float(maxIndex - 1);
                float p11 = getHistogram(featureIndex, prev); 
                float p20 = float(maxIndex);
                float p21 = getHistogram(featureIndex, maxIndex); 
                float p30 = float(maxIndex + 1);
                float p31 = getHistogram(featureIndex, next); 

                float d1 = (p30-p20)*(p30-p10);
                float d2 = (p10-p20)*(p30-p10);
                float d3 = p10-p20;

                // If any of the denominators are zero then, just use maxIndex.
                    float fbin = float(maxIndex);
                if ( abs(d1) > 0.00001 && abs(d2) > 0.00001 && abs(d3) > 0.00001) {
                float a = p10*p10;
                float b = p20*p20;

                // Solve for the coefficients A,B,C
                float A = ((p31-p21)/d1)-((p11-p21)/d2);
                float B = ((p11-p21)+(A*(b-a)))/d3;
                float C = p11-(A*a)-(B*p10);
                fbin = -B / (2. * A);
                }

                float an = 2.0 *${Math.PI} * (fbin + 0.5) / ${la}. - ${Math.PI};
                setOutput(an);
            }
            `}; Mp[t] = e
        } return Mp[t]
    } const wH = { kernelName: "ComputeExtremaAngles", backendName: "webgl", kernelFunc: n => { const { histograms: t } = n.inputs, e = n.backend, s = CH(t); return e.runWebGLProgram(s, [t], t.dtype) } }, dI = 7, Fp = {}; function vH(n, t) {
        const e = `${n}|${t.shape[0]}`; if (!Fp.hasOwnProperty(e)) {
            const s = []; for (let i = 1; i < n; i++)s.push("image" + i); let o = "float getPixel(int octave, int y, int x) {"; for (let i = 1; i < n; i++)o += `
  if (octave == ${i}) {
	return getImage${i}(y, x);
  }
`; o += "}"; const r = {
                variableNames: [...s, "extrema", "angles", "freakPoints"], outputShape: [t.shape[0], So.length], userCode: `
  ${o}
  void main() {
	ivec2 coords = getOutputCoords();
	int featureIndex = coords[0];
	int freakIndex = coords[1];

	float freakSigma = getFreakPoints(freakIndex, 0);
	float freakX = getFreakPoints(freakIndex, 1);
	float freakY = getFreakPoints(freakIndex, 2);

	int octave = int(getExtrema(featureIndex, 1));
	float inputY = getExtrema(featureIndex, 2);
	float inputX = getExtrema(featureIndex, 3);
	float inputAngle = getAngles(featureIndex);
	float cos = ${dI}. * cos(inputAngle);
	float sin = ${dI}. * sin(inputAngle);

	float yp = inputY + freakX * sin + freakY * cos;
	float xp = inputX + freakX * cos + freakY * -sin;

	int x0 = int(floor(xp));
	int x1 = x0 + 1;
	int y0 = int(floor(yp));
	int y1 = y0 + 1;

	float f1 = getPixel(octave, y0, x0);
	float f2 = getPixel(octave, y0, x1);
	float f3 = getPixel(octave, y1, x0);
	float f4 = getPixel(octave, y1, x1);

	float x1f = float(x1);
	float y1f = float(y1);
	float x0f = float(x0);
	float y0f = float(y0);

	// ratio for interpolation between four neighbouring points
	float value = (x1f - xp) * (y1f - yp) * f1
		+ (xp - x0f) * (y1f - yp) * f2
		+ (x1f - xp) * (yp - y0f) * f3
		+ (xp - x0f) * (yp - y0f) * f4;

	setOutput(value);
  }
`}; Fp[e] = r
        } return Fp[e]
    } const SH = { kernelName: "ComputeExtremaFreak", backendName: "webgl", kernelFunc: n => { const { gaussianImagesT: t, prunedExtremas: e, prunedExtremasAngles: s, freakPointsT: o, pyramidImagesLength: r } = n.inputs, i = n.backend, a = vH(r, e); return i.runWebGLProgram(a, [...t, e, s, o], "float32") } }, hI = (So.length - 1) * So.length / 2, kH = Math.ceil(hI / 8), Vp = {}; function TH(n) {
        const t = `${n.shape[0]}`; if (!Vp.hasOwnProperty(t)) {
            const e = {
                variableNames: ["freak", "p"], outputShape: [n.shape[0], kH], userCode: `
  void main() {
    ivec2 coords = getOutputCoords();
    int featureIndex = coords[0];
    int descIndex = coords[1] * 8;

    int sum = 0;
    for (int i = 0; i < 8; i++) {
      if (descIndex + i >= ${hI}) {
        continue;
      }

      int p1 = int(getP(descIndex + i, 0));
      int p2 = int(getP(descIndex + i, 1));

      float v1 = getFreak(featureIndex, p1);
      float v2 = getFreak(featureIndex, p2);

      if (v1 < v2 + 0.01) {
        sum += int(pow(2.0, float(7 - i)));
      }
    }
    setOutput(float(sum));
  }
`}; Vp[t] = e
        } return Vp[t]
    } const NH = { kernelName: "ComputeFreakDescriptors", backendName: "webgl", kernelFunc: n => { const { extremaFreaks: t, positionT: e } = n.inputs, { backend: s } = n, o = TH(t); return s.runWebGLProgram(o, [t, e], "int32") } }, zp = {}; function RH(n, t) {
        const e = `${n}|${t}`; if (!zp.hasOwnProperty(e)) {
            const s = []; let o = "float getPixel(int octave, int y, int x) {"; for (let r = 1; r < n; r++)s.push("image" + r), o += `
				if (octave == ${r}) {
					return getImage${r}(y, x);
				}
			`; o += "}", zp[e] = {
                variableNames: [...s, "extrema"], outputShape: [t, 3, 3], userCode: `
			${o}
		
			void main() {
				ivec3 coords = getOutputCoords();
				int featureIndex = coords[0];
				float score = getExtrema(featureIndex, 0);
				if (score == 0.0) {
					return;
				}
		
				int dy = coords[1]-1;
				int dx = coords[2]-1;
				int octave = int(getExtrema(featureIndex, 1));
				int y = int(getExtrema(featureIndex, 2));
				int x = int(getExtrema(featureIndex, 3));
				setOutput(getPixel(octave, y+dy, x+dx));
			}
			`}
        } return zp[e]
    } const $H = { kernelName: "ComputeLocalization", backendName: "webgl", kernelFunc: n => { const { prunedExtremasList: t, dogPyramidImagesT: e } = n.inputs, s = n.backend, o = RH(e.length, t.length), r = qe(t, [t.length, t[0].length], "int32"); return s.runWebGLProgram(o, [...e.slice(1), r], e[0].dtype) } }, GH = .159154943091895, mr = 36, Xp = {}; function LH(n, t, e) {
        const s = `${e}|${n.shape[0]}|${t.shape[0]}`; if (!Xp.hasOwnProperty(s)) {
            const o = []; for (let c = 1; c < e; c++)o.push("image" + c); let r = "float getPixel(int octave, int y, int x) {"; for (let c = 1; c < e; c++)r += `
            if (octave == ${c}) {
                return getImage${c}(y, x);
            }
            `; r += "}"; const i = {
                variableNames: [...o, "extrema", "radial"], outputShape: [n.shape[0], t.shape[0], 2], userCode: `
                ${r}

                void main() {
                    ivec3 coords = getOutputCoords();
                    int featureIndex = coords[0];
                    int radialIndex = coords[1];
                    int propertyIndex = coords[2];

                    int radialY = int(getRadial(radialIndex, 0));
                    int radialX = int(getRadial(radialIndex, 1));
                    float radialW = getRadial(radialIndex, 2);

                    int octave = int(getExtrema(featureIndex, 1));
                    int y = int(getExtrema(featureIndex, 2));
                    int x = int(getExtrema(featureIndex, 3));

                    int xp = x + radialX;
                    int yp = y + radialY;

                    float dy = getPixel(octave, yp+1, xp) - getPixel(octave, yp-1, xp);
                    float dx = getPixel(octave, yp, xp+1) - getPixel(octave, yp, xp-1);

                    if (propertyIndex == 0) {
                    // be careful that atan(0, 0) gives 1.57 instead of 0 (different from js), but doesn't matter here, coz magnitude is 0
                    
                    float angle = atan(dy, dx) + ${Math.PI};
                    float fbin = angle * ${mr}. * ${GH};
                    setOutput(fbin);
                    return;
                    }

                    if (propertyIndex == 1) {
                        float mag = sqrt(dx * dx + dy * dy);
                        float magnitude = radialW * mag;
                        setOutput(magnitude);
                        return;
                    }
                }

                `}, a = {
                    variableNames: ["fbinMag"], outputShape: [n.shape[0], mr], userCode: `
            void main() {
                ivec2 coords = getOutputCoords();
                int featureIndex = coords[0];
                int binIndex = coords[1];

                float sum = 0.;
                for (int i = 0; i < ${t.shape[0]}; i++) {
                    float fbin = getFbinMag(featureIndex, i, 0);
                    int bin = int(floor(fbin - 0.5));
                    int b1 = imod(bin + ${mr}, ${mr});
                    int b2 = imod(bin + 1 + ${mr}, ${mr});

                    if (b1 == binIndex || b2 == binIndex) {
                        float magnitude = getFbinMag(featureIndex, i, 1);
                        float w2 = fbin - float(bin) - 0.5;
                        float w1 = w2 * -1. + 1.;

                        if (b1 == binIndex) {
                            sum += w1 * magnitude;
                        }
                        if (b2 == binIndex) {
                            sum += w2 * magnitude;
                        }
                    }
                }
                setOutput(sum);
            }
            `}; Xp[s] = [i, a]
        } return Xp[s]
    } const EH = { kernelName: "ComputeOrientationHistograms", backendName: "webgl", kernelFunc: n => { const { gaussianImagesT: t, prunedExtremasT: e, radialPropertiesT: s, pyramidImagesLength: o } = n.inputs, r = n.backend, [i, a] = LH(e, s, o), c = r.runWebGLProgram(i, [...t, e, s], s.dtype), l = r.runWebGLProgram(a, [c], s.dtype); return r.disposeIntermediateTensorInfo(c), l } }, Ap = {}; function DH(n) {
        const t = n.shape[1], e = n.shape[0], s = "w" + t + "h" + e; if (!Ap.hasOwnProperty(s)) {
            const o = {
                variableNames: ["p"], outputShape: [Math.floor(e / 2), Math.floor(t / 2)], userCode: `
            void main() {
                ivec2 coords = getOutputCoords();
                int y = coords[0] * 2;
                int x = coords[1] * 2;
        
                float sum = getP(y, x) * 0.25;
                sum += getP(y+1,x) * 0.25; 
                sum += getP(y, x+1) * 0.25; 
                sum += getP(y+1,x+1) * 0.25;
                setOutput(sum);
            }
            `}; Ap[s] = o
        } return Ap[s]
    } const WH = { kernelName: "DownsampleBilinear", backendName: "webgl", kernelFunc: n => { const t = n.inputs.image, e = n.backend, s = DH(t); return e.runWebGLProgram(s, [t], t.dtype) } }, MH = {
        kernelName: "ExtremaReduction", backendName: "webgl", kernelFunc: n => {
            const { extremasResultT: t } = n.inputs, e = n.backend, s = t.shape[0], o = t.shape[1], r = {
                variableNames: ["extrema"], outputShape: [Math.floor(s / 2), Math.floor(o / 2)], userCode: `
		  void main() {
			ivec2 coords = getOutputCoords();
			int y = coords[0] * 2;
			int x = coords[1] * 2;
  
			float location = 0.0;
			float values = getExtrema(y, x);
  
			if (getExtrema(y+1, x) != 0.0) {
			  location = 1.0;
		  values = getExtrema(y+1, x);
			}
			else if (getExtrema(y, x+1) != 0.0) {
			  location = 2.0;
		  values = getExtrema(y, x+1);
			}
			else if (getExtrema(y+1, x+1) != 0.0) {
			  location = 3.0;
		  values = getExtrema(y+1, x+1);
			}
  
			if (values < 0.0) {
			  setOutput(location * -1000.0 + values);
			} else {
			  setOutput(location * 1000.0 + values);
			}
		  }
		`}; return e.runWebGLProgram(r, [t], t.dtype)
        }
    }, Ml = 36, FH = 5, Op = {}; function VH(n) {
        const t = `h${n.shape[0]}`; if (!Op.hasOwnProperty(t)) {
            const e = {
                variableNames: ["histogram"], outputShape: [n.shape[0], Ml], userCode: `
            void main() {
                ivec2 coords = getOutputCoords();

                int featureIndex = coords[0];
                int binIndex = coords[1];

                int prevBin = imod(binIndex - 1 + ${Ml}, ${Ml});
                int nextBin = imod(binIndex + 1, ${Ml});
                float result = 0.274068619061197 * getHistogram(featureIndex, prevBin) + 0.451862761877606 * getHistogram(featureIndex, binIndex) + 0.274068619061197 * getHistogram(featureIndex, nextBin);

                setOutput(result);
            }
            `}; Op[t] = e
        } return Op[t]
    } const zH = { kernelName: "SmoothHistograms", backendName: "webgl", kernelFunc: n => { let { histograms: t } = n.inputs; const e = n.backend, s = VH(t); for (let o = 0; o < FH; o++) { const r = t; t = e.runWebGLProgram(s, [t], t.dtype), o > 0 && e.disposeIntermediateTensorInfo(r) } return t } }, Pp = {}; function XH(n, t) {
        const e = t.shape[1], s = t.shape[0], o = "w" + e + "h" + s; if (!Pp.hasOwnProperty(o)) {
            const r = {
                variableNames: ["p"], outputShape: [s, e], userCode: `
              void main() {
                ivec2 coords = getOutputCoords();
                int j = coords[0];
                int i = coords[1];
        
                float sj = 0.5 * float(j) - 0.25; 
                float si = 0.5 * float(i) - 0.25;
        
                float sj0 = floor(sj);
                float sj1 = ceil(sj);
                float si0 = floor(si);
                float si1 = ceil(si);
        
                int sj0I = int(sj0);
                int sj1I = int(sj1);
                int si0I = int(si0);
                int si1I = int(si1);
        
                float sum = 0.0;
                sum += getP(sj0I, si0I) * (si1 - si) * (sj1 - sj);
                sum += getP(sj1I, si0I) * (si1 - si) * (sj - sj0);
                sum += getP(sj0I, si1I) * (si - si0) * (sj1 - sj);
                sum += getP(sj1I, si1I) * (si - si0) * (sj - sj0);
                setOutput(sum);
              }
            `}; Pp[o] = r
        } return Pp[o]
    } const AH = { kernelName: "UpsampleBilinear", backendName: "webgl", kernelFunc: n => { const { image: t, targetImage: e } = n.inputs, s = n.backend, o = XH(t, e); return s.runWebGLProgram(o, [t], t.dtype) } }; Je(gH), Je(IH), Je(wH), Je(SH), Je(NH), Je($H), Je(EH), Je(WH), Je(MH), Je(zH), Je(AH); const pI = 8, OH = 5, ua = 10, PH = 5, Kp = 3, KH = 1.5; (So.length - 1) * So.length / 2; class fI { constructor(t, e, s = !1) { this.debugMode = s, this.width = t, this.height = e; let o = 0; for (; t >= pI && e >= pI && (t /= 2, e /= 2, o++, o !== OH);); this.numOctaves = o, this.tensorCaches = {}, this.kernelCaches = {} } detectImageData(t) { const e = new Uint8ClampedArray(4 * t.length); for (let o = 0; o < t.length; o++)e[4 * o] = t[o], e[4 * o + 1] = t[o], e[4 * o + 2] = t[o], e[4 * o + 3] = 255; const s = new ImageData(e, this.width, this.height); return this.detect(s) } detect(t) { let e = null; const s = []; for (let b = 0; b < this.numOctaves; b++) { let x, I; b === 0 ? x = this._applyFilter(t) : x = this._downsampleBilinear(s[b - 1][s[b - 1].length - 1]), I = this._applyFilter(x), s.push([x, I]) } const o = []; for (let b = 0; b < this.numOctaves; b++) { let x = this._differenceImageBinomial(s[b][0], s[b][1]); o.push(x) } const r = []; for (let b = 1; b < this.numOctaves - 1; b++) { const x = this._buildExtremas(o[b - 1], o[b], o[b + 1]); r.push(x) } const i = this._applyPrune(r), a = this._computeLocalization(i, o), c = this._computeOrientationHistograms(a, s), l = this._smoothHistograms(c), u = this._computeExtremaAngles(l), d = this._computeExtremaFreak(s, a, u), h = this._computeFreakDescriptors(d), p = a.arraySync(), f = u.arraySync(), m = h.arraySync(); this.debugMode && (e = { pyramidImages: s.map(b => b.map(x => x.arraySync())), dogPyramidImages: o.map(b => b ? b.arraySync() : null), extremasResults: r.map(b => b.arraySync()), extremaAngles: u.arraySync(), prunedExtremas: i, localizedExtremas: a.arraySync() }), s.forEach(b => b.forEach(x => x.dispose())), o.forEach(b => b && b.dispose()), r.forEach(b => b.dispose()), a.dispose(), c.dispose(), l.dispose(), u.dispose(), d.dispose(), h.dispose(); const g = []; for (let b = 0; b < p.length; b++) { if (p[b][0] == 0) continue; const x = []; for (let T = 0; T < m[b].length; T += 4) { const R = m[b][T], G = m[b][T + 1], F = m[b][T + 2], V = m[b][T + 3]; let z = R * 16777216 + G * 65536 + F * 256 + V; x.push(z) } const I = p[b][1], y = p[b][2], w = p[b][3] * Math.pow(2, I) + Math.pow(2, I - 1) - .5, k = y * Math.pow(2, I) + Math.pow(2, I - 1) - .5, S = Math.pow(2, I); g.push({ maxima: p[b][0] > 0, x: w, y: k, scale: S, angle: f[b], descriptors: x }) } return { featurePoints: g, debugExtra: e } } _computeFreakDescriptors(t) { if (!this.tensorCaches.computeFreakDescriptors) { const s = [], o = []; for (let a = 0; a < t.shape[1]; a++)for (let c = a + 1; c < t.shape[1]; c++)s.push(a), o.push(c); const r = qe(s, [s.length]).cast("int32"), i = qe(o, [o.length]).cast("int32"); this.tensorCaches.computeFreakDescriptors = { positionT: tn(os([r, i], 1)) } } const { positionT: e } = this.tensorCaches.computeFreakDescriptors; return M(() => Ft().runKernel("ComputeFreakDescriptors", { extremaFreaks: t, positionT: e })) } _computeExtremaFreak(t, e, s) { this.tensorCaches._computeExtremaFreak || M(() => { const i = qe(So); this.tensorCaches._computeExtremaFreak = { freakPointsT: tn(i) } }); const { freakPointsT: o } = this.tensorCaches._computeExtremaFreak, r = []; for (let i = 1; i < t.length; i++)r.push(t[i][1]); return M(() => Ft().runKernel("ComputeExtremaFreak", { gaussianImagesT: r, prunedExtremas: e, prunedExtremasAngles: s, freakPointsT: o, pyramidImagesLength: t.length })) } _computeExtremaAngles(t) { return M(() => Ft().runKernel("ComputeExtremaAngles", { histograms: t })) } _computeOrientationHistograms(t, e) { const s = []; for (let r = 1; r < e.length; r++)s.push(e[r][1]); this.tensorCaches.orientationHistograms || M(() => { const r = -1 / (2 * Kp * Kp), i = Kp * KH, a = Math.ceil(i), c = []; for (let l = -a; l <= a; l++)for (let u = -a; u <= a; u++) { const d = u * u + l * l; if (d <= i * i) { const h = d * r; let p = (720 + h * (720 + h * (360 + h * (120 + h * (30 + h * (6 + h)))))) * .0013888888; c.push([l, u, p]) } } this.tensorCaches.orientationHistograms = { radialPropertiesT: tn(qe(c, [c.length, 3])) } }); const { radialPropertiesT: o } = this.tensorCaches.orientationHistograms; return M(() => Ft().runKernel("ComputeOrientationHistograms", { gaussianImagesT: s, prunedExtremasT: t, radialPropertiesT: o, pyramidImagesLength: e.length })) } _smoothHistograms(t) { return M(() => Ft().runKernel("SmoothHistograms", { histograms: t })) } _computeLocalization(t, e) { return M(() => { const o = Ft().runKernel("ComputeLocalization", { prunedExtremasList: t, dogPyramidImagesT: e }).arraySync(), r = []; for (let a = 0; a < o.length; a++) { r.push([]); for (let c = 0; c < o[a].length; c++)r[a].push([]) } const i = []; for (let a = 0; a < t.length; a++)i[a] = [t[a][0], t[a][1], t[a][2], t[a][3]]; for (let a = 0; a < i.length; a++) { if (i[a][0] === 0) continue; const c = o[a], l = .5 * (c[1][2] - c[1][0]), u = .5 * (c[2][1] - c[0][1]), d = c[1][2] + c[1][0] - 2 * c[1][1], h = c[2][1] + c[0][1] - 2 * c[1][1], p = .25 * (c[0][0] + c[2][2] - c[0][2] - c[2][0]), f = d * h - p * p, m = (h * -l + -p * -u) / f, g = (-p * -l + d * -u) / f, b = i[a][2] + g, x = i[a][3] + m; Math.abs(f) < 1e-4 || (i[a][2] = b, i[a][3] = x) } return qe(i, [i.length, i[0].length], "float32") }) } _applyPrune(t) { const e = ua * ua, s = PH, o = [], r = []; for (let a = 0; a < e; a++) { r.push([]), o.push([]); for (let c = 0; c < s; c++)r[a].push([0, 0, 0, 0]), o[a].push(0) } M(() => { for (let a = 0; a < t.length; a++) { const c = Ft().runKernel("ExtremaReduction", { extremasResultT: t[a] }), l = a + 1, u = c.arraySync(), d = c.shape[0], h = c.shape[1], p = h * 2 / ua, f = d * 2 / ua; for (let m = 0; m < d; m++)for (let g = 0; g < h; g++) { const b = u[m][g]; if (b == 0) continue; const x = b % 1e3, I = Math.floor(Math.abs(b) / 1e3), y = g * 2 + (I === 2 || I === 3 ? 1 : 0), C = m * 2 + (I === 1 || I === 3 ? 1 : 0), w = Math.floor(y / p), S = Math.floor(C / f) * ua + w, T = Math.abs(x); let R = s; for (; R >= 1 && T > o[S][R - 1];)R -= 1; if (R < s) { for (let G = s - 1; G >= R + 1; G--)o[S][G] = o[S][G - 1], r[S][G][0] = r[S][G - 1][0], r[S][G][1] = r[S][G - 1][1], r[S][G][2] = r[S][G - 1][2], r[S][G][3] = r[S][G - 1][3]; o[S][R] = T, r[S][R][0] = x, r[S][R][1] = l, r[S][R][2] = C, r[S][R][3] = y } } } }); const i = []; for (let a = 0; a < e; a++)for (let c = 0; c < s; c++)i.push(r[a][c]); return i } _buildExtremas(t, e, s) { return M(() => Ft().runKernel("BuildExtremas", { image0: t, image1: e, image2: s })) } _differenceImageBinomial(t, e) { return M(() => t.sub(e)) } _applyFilter(t) { return M(() => Ft().runKernel("BinomialFilter", { image: t })) } _downsampleBilinear(t) { return M(() => Ft().runKernel("DownsampleBilinear", { image: t })) } _compileAndRun(t, e) { const s = bs().compileAndRun(t, e); return Ft().makeTensorFromDataId(s.dataId, s.shape, s.dtype) } _runWebGLProgram(t, e, s) { const o = bs().runWebGLProgram(t, e, s); return Ft().makeTensorFromDataId(o.dataId, o.shape, o.dtype) } } class ZH { constructor(t, e, s = !1) { this.debugMode = s, this.width = t, this.height = e; let o = Math.min(t, e) / 2, r = Math.pow(2, Math.round(Math.log(o) / Math.log(2))); this.cropSize = r, this.detector = new fI(r, r, s), this.kernelCaches = {}, this.lastRandomIndex = 4 } detect(t) { const e = Math.floor(this.height / 2 - this.cropSize / 2), s = Math.floor(this.width / 2 - this.cropSize / 2), o = this._detect(t, s, e); return this.debugMode && (o.debugExtra.crop = { startX: s, startY: e, cropSize: this.cropSize }), o } detectMoving(t) { const e = this.lastRandomIndex % 3, s = Math.floor(this.lastRandomIndex / 3); let o = Math.floor(this.height / 2 - this.cropSize + s * this.cropSize / 2), r = Math.floor(this.width / 2 - this.cropSize + e * this.cropSize / 2); return r < 0 && (r = 0), o < 0 && (o = 0), r >= this.width - this.cropSize && (r = this.width - this.cropSize - 1), o >= this.height - this.cropSize && (o = this.height - this.cropSize - 1), this.lastRandomIndex = (this.lastRandomIndex + 1) % 9, this._detect(t, r, o) } _detect(t, e, s) { const o = t.slice([s, e], [this.cropSize, this.cropSize]), { featurePoints: r, debugExtra: i } = this.detector.detect(o); return r.forEach(a => { a.x += e, a.y += s }), this.debugMode && (i.projectedImage = o.arraySync()), o.dispose(), { featurePoints: r, debugExtra: i } } } const mI = ({ image: n, ratio: t }) => { const e = Math.round(n.width * t), s = Math.round(n.height * t), o = new Uint8Array(e * s); for (let r = 0; r < e; r++) { let i = Math.round(1 * r / t), a = Math.round(1 * (r + 1) / t) - 1; a >= n.width && (a = n.width - 1); for (let c = 0; c < s; c++) { let l = Math.round(1 * c / t), u = Math.round(1 * (c + 1) / t) - 1; u >= n.height && (u = n.height - 1); let d = 0, h = 0; for (let p = i; p <= a; p++)for (let f = l; f <= u; f++)d += 1 * n.data[f * n.width + p], h += 1; o[c * e + r] = Math.floor(d / h) } } return { data: o, width: e, height: s } }, BH = 100, HH = n => { const t = BH / Math.min(n.width, n.height), e = []; let s = t; for (; ;)if (e.push(s), s *= Math.pow(2, 1 / 3), s >= .95) { s = 1; break } e.push(s), e.reverse(); const o = []; for (let r = 0; r < e.length; r++)n.width * e[r], n.height * e[r], o.push(Object.assign(mI({ image: n, ratio: e[r] }), { scale: e[r] })); return o }, _H = n => { const t = Math.min(n.width, n.height), e = [], s = []; e.push(256 / t), e.push(128 / t); for (let o = 0; o < e.length; o++)s.push(Object.assign(mI({ image: n, ratio: e[o] }), { scale: e[o] })); return s }, UH = n => { const { v1: t, v2: e } = n; let s = 0; for (let o = 0; o < t.length; o++) { let r = (t[o] ^ e[o]) >>> 0; s += YH(r) } return s }, YH = n => { var t = n - (n >> 1 & 1431655765); return t = (t >> 2 & 858993459) + (t & 858993459), t = (t >> 4) + t & 252645135, t = (t >> 8) + t & 16711935, t = (t >> 16) + t & 65535, t }, QH = 1234, JH = () => ({ seed: QH, arrayShuffle(t) { const { arr: e, sampleSize: s } = t; for (let o = 0; o < s; o++) { this.seed = (214013 * this.seed + 2531011) % -2147483648; let r = this.seed >> 16 & 32767; r = r % e.length; let i = e[o]; e[o] = e[r], e[r] = i } }, nextInt(t) { this.seed = (214013 * this.seed + 2531011) % -2147483648; let e = this.seed >> 16 & 32767; return e = e % t, e } }), jH = 16, qH = 128, Zp = 8, t9 = n => { const { points: t, pointIndexes: e, randomizer: s } = n, o = []; for (let c = 0; c < e.length; c++)o.push(c); let r = Number.MAX_SAFE_INTEGER, i = -1; const a = []; for (let c = 0; c < qH; c++) { s.arrayShuffle({ arr: o, sampleSize: Zp }); let l = 0; const u = []; for (let d = 0; d < e.length; d++) { let h = Number.MAX_SAFE_INTEGER; for (let p = 0; p < Zp; p++) { const f = e[o[p]], m = UH({ v1: t[e[d]].descriptors, v2: t[f].descriptors }); m < h && (u[d] = o[p], h = m) } l += h } a.push(u), l < r && (r = l, i = c) } return a[i] }, gI = ({ points: n }) => { const t = []; for (let o = 0; o < n.length; o++)t.push(o); const e = JH(); return { rootNode: bI({ points: n, pointIndexes: t, centerPointIndex: null, randomizer: e }) } }, bI = n => { const { points: t, pointIndexes: e, centerPointIndex: s, randomizer: o } = n; let r = !1; (e.length <= Zp || e.length <= jH) && (r = !0); const i = {}; if (!r) { const c = t9({ points: t, pointIndexes: e, randomizer: o }); for (let l = 0; l < c.length; l++)i[e[c[l]]] === void 0 && (i[e[c[l]]] = []), i[e[c[l]]].push(e[l]) } Object.keys(i).length === 1 && (r = !0); const a = { centerPointIndex: s }; if (r) { a.leaf = !0, a.pointIndexes = []; for (let c = 0; c < e.length; c++)a.pointIndexes.push(e[c]); return a } return a.leaf = !1, a.children = [], Object.keys(i).forEach(c => { a.children.push(bI({ points: t, pointIndexes: i[c], centerPointIndex: c, randomizer: o })) }), a }; var ko = 4294967295; function e9(n, t, e) { var s = e / 4294967296, o = e; n.setUint32(t, s), n.setUint32(t + 4, o) } function xI(n, t, e) { var s = Math.floor(e / 4294967296), o = e; n.setUint32(t, s), n.setUint32(t + 4, o) } function yI(n, t) { var e = n.getInt32(t), s = n.getUint32(t + 4); return e * 4294967296 + s } function n9(n, t) { var e = n.getUint32(t), s = n.getUint32(t + 4); return e * 4294967296 + s } var Bp, Hp, _p, Fl = (typeof process > "u" || ((Bp = process == null ? void 0 : process.env) === null || Bp === void 0 ? void 0 : Bp.TEXT_ENCODING) !== "never") && typeof TextEncoder < "u" && typeof TextDecoder < "u"; function II(n) { for (var t = n.length, e = 0, s = 0; s < t;) { var o = n.charCodeAt(s++); if (o & 4294967168) if (!(o & 4294965248)) e += 2; else { if (o >= 55296 && o <= 56319 && s < t) { var r = n.charCodeAt(s); (r & 64512) === 56320 && (++s, o = ((o & 1023) << 10) + (r & 1023) + 65536) } o & 4294901760 ? e += 4 : e += 3 } else { e++; continue } } return e } function s9(n, t, e) { for (var s = n.length, o = e, r = 0; r < s;) { var i = n.charCodeAt(r++); if (i & 4294967168) if (!(i & 4294965248)) t[o++] = i >> 6 & 31 | 192; else { if (i >= 55296 && i <= 56319 && r < s) { var a = n.charCodeAt(r); (a & 64512) === 56320 && (++r, i = ((i & 1023) << 10) + (a & 1023) + 65536) } i & 4294901760 ? (t[o++] = i >> 18 & 7 | 240, t[o++] = i >> 12 & 63 | 128, t[o++] = i >> 6 & 63 | 128) : (t[o++] = i >> 12 & 15 | 224, t[o++] = i >> 6 & 63 | 128) } else { t[o++] = i; continue } t[o++] = i & 63 | 128 } } var da = Fl ? new TextEncoder : void 0, o9 = Fl ? typeof process < "u" && ((Hp = process == null ? void 0 : process.env) === null || Hp === void 0 ? void 0 : Hp.TEXT_ENCODING) !== "force" ? 200 : 0 : ko; function r9(n, t, e) { t.set(da.encode(n), e) } function i9(n, t, e) { da.encodeInto(n, t.subarray(e)) } var a9 = da != null && da.encodeInto ? i9 : r9, c9 = 4096; function CI(n, t, e) { for (var s = t, o = s + e, r = [], i = ""; s < o;) { var a = n[s++]; if (!(a & 128)) r.push(a); else if ((a & 224) === 192) { var c = n[s++] & 63; r.push((a & 31) << 6 | c) } else if ((a & 240) === 224) { var c = n[s++] & 63, l = n[s++] & 63; r.push((a & 31) << 12 | c << 6 | l) } else if ((a & 248) === 240) { var c = n[s++] & 63, l = n[s++] & 63, u = n[s++] & 63, d = (a & 7) << 18 | c << 12 | l << 6 | u; d > 65535 && (d -= 65536, r.push(d >>> 10 & 1023 | 55296), d = 56320 | d & 1023), r.push(d) } else r.push(a); r.length >= c9 && (i += String.fromCharCode.apply(String, r), r.length = 0) } return r.length > 0 && (i += String.fromCharCode.apply(String, r)), i } var l9 = Fl ? new TextDecoder : null, u9 = Fl ? typeof process < "u" && ((_p = process == null ? void 0 : process.env) === null || _p === void 0 ? void 0 : _p.TEXT_DECODER) !== "force" ? 200 : 0 : ko; function d9(n, t, e) { var s = n.subarray(t, t + e); return l9.decode(s) } var Vl = function () { function n(t, e) { this.type = t, this.data = e } return n }(), h9 = globalThis && globalThis.__extends || function () { var n = function (t, e) { return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (s, o) { s.__proto__ = o } || function (s, o) { for (var r in o) Object.prototype.hasOwnProperty.call(o, r) && (s[r] = o[r]) }, n(t, e) }; return function (t, e) { if (typeof e != "function" && e !== null) throw new TypeError("Class extends value " + String(e) + " is not a constructor or null"); n(t, e); function s() { this.constructor = t } t.prototype = e === null ? Object.create(e) : (s.prototype = e.prototype, new s) } }(), Jn = function (n) { h9(t, n); function t(e) { var s = n.call(this, e) || this, o = Object.create(t.prototype); return Object.setPrototypeOf(s, o), Object.defineProperty(s, "name", { configurable: !0, enumerable: !1, value: t.name }), s } return t }(Error), p9 = -1, f9 = 4294967296 - 1, m9 = 17179869184 - 1; function g9(n) { var t = n.sec, e = n.nsec; if (t >= 0 && e >= 0 && t <= m9) if (e === 0 && t <= f9) { var s = new Uint8Array(4), o = new DataView(s.buffer); return o.setUint32(0, t), s } else { var r = t / 4294967296, i = t & 4294967295, s = new Uint8Array(8), o = new DataView(s.buffer); return o.setUint32(0, e << 2 | r & 3), o.setUint32(4, i), s } else { var s = new Uint8Array(12), o = new DataView(s.buffer); return o.setUint32(0, e), xI(o, 4, t), s } } function b9(n) { var t = n.getTime(), e = Math.floor(t / 1e3), s = (t - e * 1e3) * 1e6, o = Math.floor(s / 1e9); return { sec: e + o, nsec: s - o * 1e9 } } function x9(n) { if (n instanceof Date) { var t = b9(n); return g9(t) } else return null } function y9(n) { var t = new DataView(n.buffer, n.byteOffset, n.byteLength); switch (n.byteLength) { case 4: { var e = t.getUint32(0), s = 0; return { sec: e, nsec: s } } case 8: { var o = t.getUint32(0), r = t.getUint32(4), e = (o & 3) * 4294967296 + r, s = o >>> 2; return { sec: e, nsec: s } } case 12: { var e = yI(t, 4), s = t.getUint32(0); return { sec: e, nsec: s } } default: throw new Jn("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(n.length)) } } function I9(n) { var t = y9(n); return new Date(t.sec * 1e3 + t.nsec / 1e6) } var C9 = { type: p9, encode: x9, decode: I9 }, wI = function () { function n() { this.builtInEncoders = [], this.builtInDecoders = [], this.encoders = [], this.decoders = [], this.register(C9) } return n.prototype.register = function (t) { var e = t.type, s = t.encode, o = t.decode; if (e >= 0) this.encoders[e] = s, this.decoders[e] = o; else { var r = 1 + e; this.builtInEncoders[r] = s, this.builtInDecoders[r] = o } }, n.prototype.tryToEncode = function (t, e) { for (var s = 0; s < this.builtInEncoders.length; s++) { var o = this.builtInEncoders[s]; if (o != null) { var r = o(t, e); if (r != null) { var i = -1 - s; return new Vl(i, r) } } } for (var s = 0; s < this.encoders.length; s++) { var o = this.encoders[s]; if (o != null) { var r = o(t, e); if (r != null) { var i = s; return new Vl(i, r) } } } return t instanceof Vl ? t : null }, n.prototype.decode = function (t, e, s) { var o = e < 0 ? this.builtInDecoders[-1 - e] : this.decoders[e]; return o ? o(t, e, s) : new Vl(e, t) }, n.defaultCodec = new n, n }(); function zl(n) { return n instanceof Uint8Array ? n : ArrayBuffer.isView(n) ? new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : n instanceof ArrayBuffer ? new Uint8Array(n) : Uint8Array.from(n) } function w9(n) { if (n instanceof ArrayBuffer) return new DataView(n); var t = zl(n); return new DataView(t.buffer, t.byteOffset, t.byteLength) } var v9 = 100, S9 = 2048, k9 = function () { function n(t, e, s, o, r, i, a, c) { t === void 0 && (t = wI.defaultCodec), e === void 0 && (e = void 0), s === void 0 && (s = v9), o === void 0 && (o = S9), r === void 0 && (r = !1), i === void 0 && (i = !1), a === void 0 && (a = !1), c === void 0 && (c = !1), this.extensionCodec = t, this.context = e, this.maxDepth = s, this.initialBufferSize = o, this.sortKeys = r, this.forceFloat32 = i, this.ignoreUndefined = a, this.forceIntegerToFloat = c, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer) } return n.prototype.reinitializeState = function () { this.pos = 0 }, n.prototype.encodeSharedRef = function (t) { return this.reinitializeState(), this.doEncode(t, 1), this.bytes.subarray(0, this.pos) }, n.prototype.encode = function (t) { return this.reinitializeState(), this.doEncode(t, 1), this.bytes.slice(0, this.pos) }, n.prototype.doEncode = function (t, e) { if (e > this.maxDepth) throw new Error("Too deep objects in depth ".concat(e)); t == null ? this.encodeNil() : typeof t == "boolean" ? this.encodeBoolean(t) : typeof t == "number" ? this.encodeNumber(t) : typeof t == "string" ? this.encodeString(t) : this.encodeObject(t, e) }, n.prototype.ensureBufferSizeToWrite = function (t) { var e = this.pos + t; this.view.byteLength < e && this.resizeBuffer(e * 2) }, n.prototype.resizeBuffer = function (t) { var e = new ArrayBuffer(t), s = new Uint8Array(e), o = new DataView(e); s.set(this.bytes), this.view = o, this.bytes = s }, n.prototype.encodeNil = function () { this.writeU8(192) }, n.prototype.encodeBoolean = function (t) { t === !1 ? this.writeU8(194) : this.writeU8(195) }, n.prototype.encodeNumber = function (t) { Number.isSafeInteger(t) && !this.forceIntegerToFloat ? t >= 0 ? t < 128 ? this.writeU8(t) : t < 256 ? (this.writeU8(204), this.writeU8(t)) : t < 65536 ? (this.writeU8(205), this.writeU16(t)) : t < 4294967296 ? (this.writeU8(206), this.writeU32(t)) : (this.writeU8(207), this.writeU64(t)) : t >= -32 ? this.writeU8(224 | t + 32) : t >= -128 ? (this.writeU8(208), this.writeI8(t)) : t >= -32768 ? (this.writeU8(209), this.writeI16(t)) : t >= -2147483648 ? (this.writeU8(210), this.writeI32(t)) : (this.writeU8(211), this.writeI64(t)) : this.forceFloat32 ? (this.writeU8(202), this.writeF32(t)) : (this.writeU8(203), this.writeF64(t)) }, n.prototype.writeStringHeader = function (t) { if (t < 32) this.writeU8(160 + t); else if (t < 256) this.writeU8(217), this.writeU8(t); else if (t < 65536) this.writeU8(218), this.writeU16(t); else if (t < 4294967296) this.writeU8(219), this.writeU32(t); else throw new Error("Too long string: ".concat(t, " bytes in UTF-8")) }, n.prototype.encodeString = function (t) { var e = 5, s = t.length; if (s > o9) { var o = II(t); this.ensureBufferSizeToWrite(e + o), this.writeStringHeader(o), a9(t, this.bytes, this.pos), this.pos += o } else { var o = II(t); this.ensureBufferSizeToWrite(e + o), this.writeStringHeader(o), s9(t, this.bytes, this.pos), this.pos += o } }, n.prototype.encodeObject = function (t, e) { var s = this.extensionCodec.tryToEncode(t, this.context); if (s != null) this.encodeExtension(s); else if (Array.isArray(t)) this.encodeArray(t, e); else if (ArrayBuffer.isView(t)) this.encodeBinary(t); else if (typeof t == "object") this.encodeMap(t, e); else throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(t))) }, n.prototype.encodeBinary = function (t) { var e = t.byteLength; if (e < 256) this.writeU8(196), this.writeU8(e); else if (e < 65536) this.writeU8(197), this.writeU16(e); else if (e < 4294967296) this.writeU8(198), this.writeU32(e); else throw new Error("Too large binary: ".concat(e)); var s = zl(t); this.writeU8a(s) }, n.prototype.encodeArray = function (t, e) { var s = t.length; if (s < 16) this.writeU8(144 + s); else if (s < 65536) this.writeU8(220), this.writeU16(s); else if (s < 4294967296) this.writeU8(221), this.writeU32(s); else throw new Error("Too large array: ".concat(s)); for (var o = 0, r = t; o < r.length; o++) { var i = r[o]; this.doEncode(i, e + 1) } }, n.prototype.countWithoutUndefined = function (t, e) { for (var s = 0, o = 0, r = e; o < r.length; o++) { var i = r[o]; t[i] !== void 0 && s++ } return s }, n.prototype.encodeMap = function (t, e) { var s = Object.keys(t); this.sortKeys && s.sort(); var o = this.ignoreUndefined ? this.countWithoutUndefined(t, s) : s.length; if (o < 16) this.writeU8(128 + o); else if (o < 65536) this.writeU8(222), this.writeU16(o); else if (o < 4294967296) this.writeU8(223), this.writeU32(o); else throw new Error("Too large map object: ".concat(o)); for (var r = 0, i = s; r < i.length; r++) { var a = i[r], c = t[a]; this.ignoreUndefined && c === void 0 || (this.encodeString(a), this.doEncode(c, e + 1)) } }, n.prototype.encodeExtension = function (t) { var e = t.data.length; if (e === 1) this.writeU8(212); else if (e === 2) this.writeU8(213); else if (e === 4) this.writeU8(214); else if (e === 8) this.writeU8(215); else if (e === 16) this.writeU8(216); else if (e < 256) this.writeU8(199), this.writeU8(e); else if (e < 65536) this.writeU8(200), this.writeU16(e); else if (e < 4294967296) this.writeU8(201), this.writeU32(e); else throw new Error("Too large extension object: ".concat(e)); this.writeI8(t.type), this.writeU8a(t.data) }, n.prototype.writeU8 = function (t) { this.ensureBufferSizeToWrite(1), this.view.setUint8(this.pos, t), this.pos++ }, n.prototype.writeU8a = function (t) { var e = t.length; this.ensureBufferSizeToWrite(e), this.bytes.set(t, this.pos), this.pos += e }, n.prototype.writeI8 = function (t) { this.ensureBufferSizeToWrite(1), this.view.setInt8(this.pos, t), this.pos++ }, n.prototype.writeU16 = function (t) { this.ensureBufferSizeToWrite(2), this.view.setUint16(this.pos, t), this.pos += 2 }, n.prototype.writeI16 = function (t) { this.ensureBufferSizeToWrite(2), this.view.setInt16(this.pos, t), this.pos += 2 }, n.prototype.writeU32 = function (t) { this.ensureBufferSizeToWrite(4), this.view.setUint32(this.pos, t), this.pos += 4 }, n.prototype.writeI32 = function (t) { this.ensureBufferSizeToWrite(4), this.view.setInt32(this.pos, t), this.pos += 4 }, n.prototype.writeF32 = function (t) { this.ensureBufferSizeToWrite(4), this.view.setFloat32(this.pos, t), this.pos += 4 }, n.prototype.writeF64 = function (t) { this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, t), this.pos += 8 }, n.prototype.writeU64 = function (t) { this.ensureBufferSizeToWrite(8), e9(this.view, this.pos, t), this.pos += 8 }, n.prototype.writeI64 = function (t) { this.ensureBufferSizeToWrite(8), xI(this.view, this.pos, t), this.pos += 8 }, n }(), T9 = {}; function N9(n, t) { t === void 0 && (t = T9); var e = new k9(t.extensionCodec, t.context, t.maxDepth, t.initialBufferSize, t.sortKeys, t.forceFloat32, t.ignoreUndefined, t.forceIntegerToFloat); return e.encodeSharedRef(n) } function Up(n) { return "".concat(n < 0 ? "-" : "", "0x").concat(Math.abs(n).toString(16).padStart(2, "0")) } var R9 = 16, $9 = 16, G9 = function () { function n(t, e) { t === void 0 && (t = R9), e === void 0 && (e = $9), this.maxKeyLength = t, this.maxLengthPerKey = e, this.hit = 0, this.miss = 0, this.caches = []; for (var s = 0; s < this.maxKeyLength; s++)this.caches.push([]) } return n.prototype.canBeCached = function (t) { return t > 0 && t <= this.maxKeyLength }, n.prototype.find = function (t, e, s) { var o = this.caches[s - 1]; t: for (var r = 0, i = o; r < i.length; r++) { for (var a = i[r], c = a.bytes, l = 0; l < s; l++)if (c[l] !== t[e + l]) continue t; return a.str } return null }, n.prototype.store = function (t, e) { var s = this.caches[t.length - 1], o = { bytes: t, str: e }; s.length >= this.maxLengthPerKey ? s[Math.random() * s.length | 0] = o : s.push(o) }, n.prototype.decode = function (t, e, s) { var o = this.find(t, e, s); if (o != null) return this.hit++, o; this.miss++; var r = CI(t, e, s), i = Uint8Array.prototype.slice.call(t, e, e + s); return this.store(i, r), r }, n }(), L9 = globalThis && globalThis.__awaiter || function (n, t, e, s) { function o(r) { return r instanceof e ? r : new e(function (i) { i(r) }) } return new (e || (e = Promise))(function (r, i) { function a(u) { try { l(s.next(u)) } catch (d) { i(d) } } function c(u) { try { l(s.throw(u)) } catch (d) { i(d) } } function l(u) { u.done ? r(u.value) : o(u.value).then(a, c) } l((s = s.apply(n, t || [])).next()) }) }, Yp = globalThis && globalThis.__generator || function (n, t) { var e = { label: 0, sent: function () { if (r[0] & 1) throw r[1]; return r[1] }, trys: [], ops: [] }, s, o, r, i; return i = { next: a(0), throw: a(1), return: a(2) }, typeof Symbol == "function" && (i[Symbol.iterator] = function () { return this }), i; function a(l) { return function (u) { return c([l, u]) } } function c(l) { if (s) throw new TypeError("Generator is already executing."); for (; e;)try { if (s = 1, o && (r = l[0] & 2 ? o.return : l[0] ? o.throw || ((r = o.return) && r.call(o), 0) : o.next) && !(r = r.call(o, l[1])).done) return r; switch (o = 0, r && (l = [l[0] & 2, r.value]), l[0]) { case 0: case 1: r = l; break; case 4: return e.label++, { value: l[1], done: !1 }; case 5: e.label++, o = l[1], l = [0]; continue; case 7: l = e.ops.pop(), e.trys.pop(); continue; default: if (r = e.trys, !(r = r.length > 0 && r[r.length - 1]) && (l[0] === 6 || l[0] === 2)) { e = 0; continue } if (l[0] === 3 && (!r || l[1] > r[0] && l[1] < r[3])) { e.label = l[1]; break } if (l[0] === 6 && e.label < r[1]) { e.label = r[1], r = l; break } if (r && e.label < r[2]) { e.label = r[2], e.ops.push(l); break } r[2] && e.ops.pop(), e.trys.pop(); continue }l = t.call(n, e) } catch (u) { l = [6, u], o = 0 } finally { s = r = 0 } if (l[0] & 5) throw l[1]; return { value: l[0] ? l[1] : void 0, done: !0 } } }, vI = globalThis && globalThis.__asyncValues || function (n) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var t = n[Symbol.asyncIterator], e; return t ? t.call(n) : (n = typeof __values == "function" ? __values(n) : n[Symbol.iterator](), e = {}, s("next"), s("throw"), s("return"), e[Symbol.asyncIterator] = function () { return this }, e); function s(r) { e[r] = n[r] && function (i) { return new Promise(function (a, c) { i = n[r](i), o(a, c, i.done, i.value) }) } } function o(r, i, a, c) { Promise.resolve(c).then(function (l) { r({ value: l, done: a }) }, i) } }, gr = globalThis && globalThis.__await || function (n) { return this instanceof gr ? (this.v = n, this) : new gr(n) }, E9 = globalThis && globalThis.__asyncGenerator || function (n, t, e) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var s = e.apply(n, t || []), o, r = []; return o = {}, i("next"), i("throw"), i("return"), o[Symbol.asyncIterator] = function () { return this }, o; function i(h) { s[h] && (o[h] = function (p) { return new Promise(function (f, m) { r.push([h, p, f, m]) > 1 || a(h, p) }) }) } function a(h, p) { try { c(s[h](p)) } catch (f) { d(r[0][3], f) } } function c(h) { h.value instanceof gr ? Promise.resolve(h.value.v).then(l, u) : d(r[0][2], h) } function l(h) { a("next", h) } function u(h) { a("throw", h) } function d(h, p) { h(p), r.shift(), r.length && a(r[0][0], r[0][1]) } }, D9 = function (n) { var t = typeof n; return t === "string" || t === "number" }, ha = -1, Qp = new DataView(new ArrayBuffer(0)), W9 = new Uint8Array(Qp.buffer), Jp = function () { try { Qp.getInt8(0) } catch (n) { return n.constructor } throw new Error("never reached") }(), SI = new Jp("Insufficient data"), M9 = new G9, F9 = function () { function n(t, e, s, o, r, i, a, c) { t === void 0 && (t = wI.defaultCodec), e === void 0 && (e = void 0), s === void 0 && (s = ko), o === void 0 && (o = ko), r === void 0 && (r = ko), i === void 0 && (i = ko), a === void 0 && (a = ko), c === void 0 && (c = M9), this.extensionCodec = t, this.context = e, this.maxStrLength = s, this.maxBinLength = o, this.maxArrayLength = r, this.maxMapLength = i, this.maxExtLength = a, this.keyDecoder = c, this.totalPos = 0, this.pos = 0, this.view = Qp, this.bytes = W9, this.headByte = ha, this.stack = [] } return n.prototype.reinitializeState = function () { this.totalPos = 0, this.headByte = ha, this.stack.length = 0 }, n.prototype.setBuffer = function (t) { this.bytes = zl(t), this.view = w9(this.bytes), this.pos = 0 }, n.prototype.appendBuffer = function (t) { if (this.headByte === ha && !this.hasRemaining(1)) this.setBuffer(t); else { var e = this.bytes.subarray(this.pos), s = zl(t), o = new Uint8Array(e.length + s.length); o.set(e), o.set(s, e.length), this.setBuffer(o) } }, n.prototype.hasRemaining = function (t) { return this.view.byteLength - this.pos >= t }, n.prototype.createExtraByteError = function (t) { var e = this, s = e.view, o = e.pos; return new RangeError("Extra ".concat(s.byteLength - o, " of ").concat(s.byteLength, " byte(s) found at buffer[").concat(t, "]")) }, n.prototype.decode = function (t) { this.reinitializeState(), this.setBuffer(t); var e = this.doDecodeSync(); if (this.hasRemaining(1)) throw this.createExtraByteError(this.pos); return e }, n.prototype.decodeMulti = function (t) { return Yp(this, function (e) { switch (e.label) { case 0: this.reinitializeState(), this.setBuffer(t), e.label = 1; case 1: return this.hasRemaining(1) ? [4, this.doDecodeSync()] : [3, 3]; case 2: return e.sent(), [3, 1]; case 3: return [2] } }) }, n.prototype.decodeAsync = function (t) { var e, s, o, r; return L9(this, void 0, void 0, function () { var i, a, c, l, u, d, h, p; return Yp(this, function (f) { switch (f.label) { case 0: i = !1, f.label = 1; case 1: f.trys.push([1, 6, 7, 12]), e = vI(t), f.label = 2; case 2: return [4, e.next()]; case 3: if (s = f.sent(), !!s.done) return [3, 5]; if (c = s.value, i) throw this.createExtraByteError(this.totalPos); this.appendBuffer(c); try { a = this.doDecodeSync(), i = !0 } catch (m) { if (!(m instanceof Jp)) throw m } this.totalPos += this.pos, f.label = 4; case 4: return [3, 2]; case 5: return [3, 12]; case 6: return l = f.sent(), o = { error: l }, [3, 12]; case 7: return f.trys.push([7, , 10, 11]), s && !s.done && (r = e.return) ? [4, r.call(e)] : [3, 9]; case 8: f.sent(), f.label = 9; case 9: return [3, 11]; case 10: if (o) throw o.error; return [7]; case 11: return [7]; case 12: if (i) { if (this.hasRemaining(1)) throw this.createExtraByteError(this.totalPos); return [2, a] } throw u = this, d = u.headByte, h = u.pos, p = u.totalPos, new RangeError("Insufficient data in parsing ".concat(Up(d), " at ").concat(p, " (").concat(h, " in the current buffer)")) } }) }) }, n.prototype.decodeArrayStream = function (t) { return this.decodeMultiAsync(t, !0) }, n.prototype.decodeStream = function (t) { return this.decodeMultiAsync(t, !1) }, n.prototype.decodeMultiAsync = function (t, e) { return E9(this, arguments, function () { var o, r, i, a, c, l, u, d, h; return Yp(this, function (p) { switch (p.label) { case 0: o = e, r = -1, p.label = 1; case 1: p.trys.push([1, 13, 14, 19]), i = vI(t), p.label = 2; case 2: return [4, gr(i.next())]; case 3: if (a = p.sent(), !!a.done) return [3, 12]; if (c = a.value, e && r === 0) throw this.createExtraByteError(this.totalPos); this.appendBuffer(c), o && (r = this.readArraySize(), o = !1, this.complete()), p.label = 4; case 4: p.trys.push([4, 9, , 10]), p.label = 5; case 5: return [4, gr(this.doDecodeSync())]; case 6: return [4, p.sent()]; case 7: return p.sent(), --r === 0 ? [3, 8] : [3, 5]; case 8: return [3, 10]; case 9: if (l = p.sent(), !(l instanceof Jp)) throw l; return [3, 10]; case 10: this.totalPos += this.pos, p.label = 11; case 11: return [3, 2]; case 12: return [3, 19]; case 13: return u = p.sent(), d = { error: u }, [3, 19]; case 14: return p.trys.push([14, , 17, 18]), a && !a.done && (h = i.return) ? [4, gr(h.call(i))] : [3, 16]; case 15: p.sent(), p.label = 16; case 16: return [3, 18]; case 17: if (d) throw d.error; return [7]; case 18: return [7]; case 19: return [2] } }) }) }, n.prototype.doDecodeSync = function () { t: for (; ;) { var t = this.readHeadByte(), e = void 0; if (t >= 224) e = t - 256; else if (t < 192) if (t < 128) e = t; else if (t < 144) { var s = t - 128; if (s !== 0) { this.pushMapState(s), this.complete(); continue t } else e = {} } else if (t < 160) { var s = t - 144; if (s !== 0) { this.pushArrayState(s), this.complete(); continue t } else e = [] } else { var o = t - 160; e = this.decodeUtf8String(o, 0) } else if (t === 192) e = null; else if (t === 194) e = !1; else if (t === 195) e = !0; else if (t === 202) e = this.readF32(); else if (t === 203) e = this.readF64(); else if (t === 204) e = this.readU8(); else if (t === 205) e = this.readU16(); else if (t === 206) e = this.readU32(); else if (t === 207) e = this.readU64(); else if (t === 208) e = this.readI8(); else if (t === 209) e = this.readI16(); else if (t === 210) e = this.readI32(); else if (t === 211) e = this.readI64(); else if (t === 217) { var o = this.lookU8(); e = this.decodeUtf8String(o, 1) } else if (t === 218) { var o = this.lookU16(); e = this.decodeUtf8String(o, 2) } else if (t === 219) { var o = this.lookU32(); e = this.decodeUtf8String(o, 4) } else if (t === 220) { var s = this.readU16(); if (s !== 0) { this.pushArrayState(s), this.complete(); continue t } else e = [] } else if (t === 221) { var s = this.readU32(); if (s !== 0) { this.pushArrayState(s), this.complete(); continue t } else e = [] } else if (t === 222) { var s = this.readU16(); if (s !== 0) { this.pushMapState(s), this.complete(); continue t } else e = {} } else if (t === 223) { var s = this.readU32(); if (s !== 0) { this.pushMapState(s), this.complete(); continue t } else e = {} } else if (t === 196) { var s = this.lookU8(); e = this.decodeBinary(s, 1) } else if (t === 197) { var s = this.lookU16(); e = this.decodeBinary(s, 2) } else if (t === 198) { var s = this.lookU32(); e = this.decodeBinary(s, 4) } else if (t === 212) e = this.decodeExtension(1, 0); else if (t === 213) e = this.decodeExtension(2, 0); else if (t === 214) e = this.decodeExtension(4, 0); else if (t === 215) e = this.decodeExtension(8, 0); else if (t === 216) e = this.decodeExtension(16, 0); else if (t === 199) { var s = this.lookU8(); e = this.decodeExtension(s, 1) } else if (t === 200) { var s = this.lookU16(); e = this.decodeExtension(s, 2) } else if (t === 201) { var s = this.lookU32(); e = this.decodeExtension(s, 4) } else throw new Jn("Unrecognized type byte: ".concat(Up(t))); this.complete(); for (var r = this.stack; r.length > 0;) { var i = r[r.length - 1]; if (i.type === 0) if (i.array[i.position] = e, i.position++, i.position === i.size) r.pop(), e = i.array; else continue t; else if (i.type === 1) { if (!D9(e)) throw new Jn("The type of key must be string or number but " + typeof e); if (e === "__proto__") throw new Jn("The key __proto__ is not allowed"); i.key = e, i.type = 2; continue t } else if (i.map[i.key] = e, i.readCount++, i.readCount === i.size) r.pop(), e = i.map; else { i.key = null, i.type = 1; continue t } } return e } }, n.prototype.readHeadByte = function () { return this.headByte === ha && (this.headByte = this.readU8()), this.headByte }, n.prototype.complete = function () { this.headByte = ha }, n.prototype.readArraySize = function () { var t = this.readHeadByte(); switch (t) { case 220: return this.readU16(); case 221: return this.readU32(); default: { if (t < 160) return t - 144; throw new Jn("Unrecognized array type byte: ".concat(Up(t))) } } }, n.prototype.pushMapState = function (t) { if (t > this.maxMapLength) throw new Jn("Max length exceeded: map length (".concat(t, ") > maxMapLengthLength (").concat(this.maxMapLength, ")")); this.stack.push({ type: 1, size: t, key: null, readCount: 0, map: {} }) }, n.prototype.pushArrayState = function (t) { if (t > this.maxArrayLength) throw new Jn("Max length exceeded: array length (".concat(t, ") > maxArrayLength (").concat(this.maxArrayLength, ")")); this.stack.push({ type: 0, size: t, array: new Array(t), position: 0 }) }, n.prototype.decodeUtf8String = function (t, e) { var s; if (t > this.maxStrLength) throw new Jn("Max length exceeded: UTF-8 byte length (".concat(t, ") > maxStrLength (").concat(this.maxStrLength, ")")); if (this.bytes.byteLength < this.pos + e + t) throw SI; var o = this.pos + e, r; return this.stateIsMapKey() && (!((s = this.keyDecoder) === null || s === void 0) && s.canBeCached(t)) ? r = this.keyDecoder.decode(this.bytes, o, t) : t > u9 ? r = d9(this.bytes, o, t) : r = CI(this.bytes, o, t), this.pos += e + t, r }, n.prototype.stateIsMapKey = function () { if (this.stack.length > 0) { var t = this.stack[this.stack.length - 1]; return t.type === 1 } return !1 }, n.prototype.decodeBinary = function (t, e) { if (t > this.maxBinLength) throw new Jn("Max length exceeded: bin length (".concat(t, ") > maxBinLength (").concat(this.maxBinLength, ")")); if (!this.hasRemaining(t + e)) throw SI; var s = this.pos + e, o = this.bytes.subarray(s, s + t); return this.pos += e + t, o }, n.prototype.decodeExtension = function (t, e) { if (t > this.maxExtLength) throw new Jn("Max length exceeded: ext length (".concat(t, ") > maxExtLength (").concat(this.maxExtLength, ")")); var s = this.view.getInt8(this.pos + e), o = this.decodeBinary(t, e + 1); return this.extensionCodec.decode(o, s, this.context) }, n.prototype.lookU8 = function () { return this.view.getUint8(this.pos) }, n.prototype.lookU16 = function () { return this.view.getUint16(this.pos) }, n.prototype.lookU32 = function () { return this.view.getUint32(this.pos) }, n.prototype.readU8 = function () { var t = this.view.getUint8(this.pos); return this.pos++, t }, n.prototype.readI8 = function () { var t = this.view.getInt8(this.pos); return this.pos++, t }, n.prototype.readU16 = function () { var t = this.view.getUint16(this.pos); return this.pos += 2, t }, n.prototype.readI16 = function () { var t = this.view.getInt16(this.pos); return this.pos += 2, t }, n.prototype.readU32 = function () { var t = this.view.getUint32(this.pos); return this.pos += 4, t }, n.prototype.readI32 = function () { var t = this.view.getInt32(this.pos); return this.pos += 4, t }, n.prototype.readU64 = function () { var t = n9(this.view, this.pos); return this.pos += 8, t }, n.prototype.readI64 = function () { var t = yI(this.view, this.pos); return this.pos += 8, t }, n.prototype.readF32 = function () { var t = this.view.getFloat32(this.pos); return this.pos += 4, t }, n.prototype.readF64 = function () { var t = this.view.getFloat64(this.pos); return this.pos += 8, t }, n }(), V9 = {}; function z9(n, t) { t === void 0 && (t = V9); var e = new F9(t.extensionCodec, t.context, t.maxStrLength, t.maxBinLength, t.maxArrayLength, t.maxMapLength, t.maxExtLength); return e.decode(n) } const kI = 2; class X9 { constructor() { this.data = null } compileImageTargets(t, e) { return new Promise(async (s, o) => { const r = []; for (let l = 0; l < t.length; l++) { const u = t[l], h = this.createProcessCanvas(u).getContext("2d"); h.drawImage(u, 0, 0, u.width, u.height); const p = h.getImageData(0, 0, u.width, u.height), f = new Uint8Array(u.width * u.height); for (let g = 0; g < f.length; g++) { const b = g * 4; f[g] = Math.floor((p.data[b] + p.data[b + 1] + p.data[b + 2]) / 3) } const m = { data: f, height: u.height, width: u.width }; r.push(m) } const i = 50 / r.length; let a = 0; this.data = []; for (let l = 0; l < r.length; l++) { const u = r[l], d = HH(u), h = i / d.length, p = await A9(d, () => { a += h, e(a) }); this.data.push({ targetImage: u, imageList: d, matchingData: p }) } for (let l = 0; l < r.length; l++) { const u = _H(r[l]); this.data[l].trackingImageList = u } const c = await this.compileTrack({ progressCallback: e, targetImages: r, basePercent: 50 }); for (let l = 0; l < r.length; l++)this.data[l].trackingData = c[l]; s(this.data) }) } exportData() { const t = []; for (let s = 0; s < this.data.length; s++)t.push({ targetImage: { width: this.data[s].targetImage.width, height: this.data[s].targetImage.height }, trackingData: this.data[s].trackingData, matchingData: this.data[s].matchingData }); return N9({ v: kI, dataList: t }) } importData(t) { const e = z9(new Uint8Array(t)); if (!e.v || e.v !== kI) return console.error("Your compiled .mind might be outdated. Please recompile"), []; const { dataList: s } = e; this.data = []; for (let o = 0; o < s.length; o++)this.data.push({ targetImage: s[o].targetImage, trackingData: s[o].trackingData, matchingData: s[o].matchingData }); return this.data } createProcessCanvas(t) { console.warn("missing createProcessCanvas implementation") } compileTrack({ progressCallback: t, targetImages: e, basePercent: s }) { console.warn("missing compileTrack implementation") } } const A9 = async (n, t) => { const e = []; for (let s = 0; s < n.length; s++) { const o = n[s], r = new fI(o.width, o.height); await Mc(), M(() => { const i = qe(o.data, [o.data.length], "float32").reshape([o.height, o.width]), { featurePoints: a } = r.detect(i), c = a.filter(h => h.maxima), l = a.filter(h => !h.maxima), u = gI({ points: c }), d = gI({ points: l }); e.push({ maximaPoints: c, minimaPoints: l, maximaPointsCluster: u, minimaPointsCluster: d, width: o.width, height: o.height, scale: o.scale }), t(s) }) } return e }, TI = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NsYXNzIHp7Y29uc3RydWN0b3Iocyx0LG8pe3RoaXMuY3Vtc3VtPVtdO2ZvcihsZXQgZT0wO2U8bztlKyspe3RoaXMuY3Vtc3VtLnB1c2goW10pO2ZvcihsZXQgbj0wO248dDtuKyspdGhpcy5jdW1zdW1bZV0ucHVzaCgwKX10aGlzLmN1bXN1bVswXVswXT1zWzBdO2ZvcihsZXQgZT0xO2U8dDtlKyspdGhpcy5jdW1zdW1bMF1bZV09dGhpcy5jdW1zdW1bMF1bZS0xXStzW2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: "text/javascript;charset=utf-8" }); function O9() { let n; try { if (n = NI && (window.URL || window.webkitURL).createObjectURL(NI), !n) throw ""; return new Worker(n) } catch { return new Worker("data:application/javascript;base64," + TI) } finally { n && (window.URL || window.webkitURL).revokeObjectURL(n) } } class RI extends X9 { createProcessCanvas(t) { const e = document.createElement("canvas"); return e.width = t.width, e.height = t.height, e } compileTrack({ progressCallback: t, targetImages: e, basePercent: s }) { return new Promise((o, r) => { const i = new O9; i.onmessage = a => { a.data.type === "progress" ? t(s + a.data.percent * s / 100) : a.data.type === "compileDone" && o(a.data.list) }, i.postMessage({ type: "compile", targetImages: e }) }) } } class P9 {
        constructor(t, e) { this.width = t, this.height = e, this.texShape = [e, t]; const s = document.createElement("canvas").getContext("2d"); s.canvas.width = t, s.canvas.height = e, this.context = s, this.program = this.buildProgram(t, e); const o = bs(); this.tempPixelHandle = o.makeTensorInfo(this.texShape, "float32"), o.texData.get(this.tempPixelHandle.dataId).usage = 2 } _loadInput(t) { return M(() => { let e = tT(t); return e = e.mean(2), e }) } loadInput(t) { const e = this.context; if (e.clearRect(0, 0, this.context.canvas.width, this.context.canvas.height), t.width === this.height && t.height === this.width) { let i = this.context.canvas.width / 2, a = this.context.canvas.height / 2, c = 90; e.save(), e.translate(i, a), e.rotate(c * Math.PI / 180), e.drawImage(t, -t.width / 2, -t.height / 2), e.restore() } else this.context.drawImage(t, 0, 0, t.width, t.height); const o = bs(); return o.gpgpu.uploadPixelDataToTexture(o.getTexture(this.tempPixelHandle.dataId), this.context.canvas), this._compileAndRun(this.program, [this.tempPixelHandle]) } buildProgram(t, e) {
            const s = A().getNumber("WEBGL_VERSION") === 2 ? "texture" : "texture2D"; return {
                variableNames: ["A"], outputShape: this.texShape, userCode: `
	void main() {
	  ivec2 coords = getOutputCoords();
	  int texR = coords[0];
	  int texC = coords[1];
	  vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${t}.0, ${e}.0);

	  vec4 values = ${s}(A, uv);
	  setOutput((0.299 * values.r + 0.587 * values.g + 0.114 * values.b) * 255.0);
	}
      `}
        } _compileAndRun(t, e) { const s = bs().compileAndRun(t, e); return Ft().makeTensorFromDataId(s.dataId, s.shape, s.dtype) } _runWebGLProgram(t, e, s) { const o = bs().runWebGLProgram(t, e, s); return Ft().makeTensorFromDataId(o.dataId, o.shape, o.dtype) }
    } const $I = (n, t) => { const e = 2 * Math.PI * t * n; return e / (e + 1) }, GI = (n, t, e) => n * t + (1 - n) * e; class K9 { constructor({ minCutOff: t, beta: e }) { this.minCutOff = t, this.beta = e, this.dCutOff = .001, this.xPrev = null, this.dxPrev = null, this.tPrev = null, this.initialized = !1 } reset() { this.initialized = !1 } filter(t, e) { if (!this.initialized) return this.initialized = !0, this.xPrev = e, this.dxPrev = e.map(() => 0), this.tPrev = t, e; const { xPrev: s, tPrev: o, dxPrev: r } = this, i = t - o, a = $I(i, this.dCutOff), c = [], l = [], u = []; for (let d = 0; d < e.length; d++) { c[d] = (e[d] - s[d]) / i, l[d] = GI(a, c[d], r[d]); const h = this.minCutOff + this.beta * Math.abs(l[d]), p = $I(i, h); u[d] = GI(p, e[d], s[d]) } return this.xPrev = u, this.dxPrev = l, this.tPrev = t, u } } const jp = { memory: vc, nextFrame: Mc }, Z9 = .001, B9 = 1e3, H9 = 5, _9 = 5; class LI { constructor({ inputWidth: t, inputHeight: e, onUpdate: s = null, debugMode: o = !1, maxTrack: r = 1, warmupTolerance: i = null, missTolerance: a = null, filterMinCF: c = null, filterBeta: l = null }) { this.inputWidth = t, this.inputHeight = e, this.maxTrack = r, this.filterMinCF = c === null ? Z9 : c, this.filterBeta = l === null ? B9 : l, this.warmupTolerance = i === null ? H9 : i, this.missTolerance = a === null ? _9 : a, this.cropDetector = new ZH(this.inputWidth, this.inputHeight, o), this.inputLoader = new P9(this.inputWidth, this.inputHeight), this.markerDimensions = null, this.onUpdate = s, this.debugMode = o, this.processingVideo = !1, this.interestedTargetIndex = -1, this.trackingStates = []; const u = 10, d = 1e5, h = 45 * Math.PI / 180, p = this.inputHeight / 2 / Math.tan(h / 2); this.projectionTransform = [[p, 0, this.inputWidth / 2], [0, p, this.inputHeight / 2], [0, 0, 1]], this.projectionMatrix = this._glProjectionMatrix({ projectionTransform: this.projectionTransform, width: this.inputWidth, height: this.inputHeight, near: u, far: d }), this.worker = new oH, this.workerMatchDone = null, this.workerTrackDone = null, this.worker.onmessage = f => { f.data.type === "matchDone" && this.workerMatchDone !== null && this.workerMatchDone(f.data), f.data.type === "trackUpdateDone" && this.workerTrackDone !== null && this.workerTrackDone(f.data) } } showTFStats() { console.log(jp.memory().numTensors), console.table(jp.memory()) } addImageTargets(t) { return new Promise(async (e, s) => { const r = await (await fetch(t)).arrayBuffer(), i = this.addImageTargetsFromBuffer(r); e(i) }) } addImageTargetsFromBuffer(t) { const s = new RI().importData(t), o = [], r = [], i = []; for (let a = 0; a < s.length; a++)r.push(s[a].matchingData), o.push(s[a].trackingData), i.push([s[a].targetImage.width, s[a].targetImage.height]); return this.tracker = new fH(i, o, this.projectionTransform, this.inputWidth, this.inputHeight, this.debugMode), this.worker.postMessage({ type: "setup", inputWidth: this.inputWidth, inputHeight: this.inputHeight, projectionTransform: this.projectionTransform, debugMode: this.debugMode, matchingDataList: r }), this.markerDimensions = i, { dimensions: i, matchingDataList: r, trackingDataList: o } } dispose() { this.stopProcessVideo(), this.worker.postMessage({ type: "dispose" }) } dummyRun(t) { const e = this.inputLoader.loadInput(t); this.cropDetector.detect(e), this.tracker.dummyRun(e), e.dispose() } getProjectionMatrix() { return this.projectionMatrix } getRotatedZ90Matrix(t) { return [-t[1], t[0], t[2], t[3], -t[5], t[4], t[6], t[7], -t[9], t[8], t[10], t[11], -t[13], t[12], t[14], t[15]] } getWorldMatrix(t, e) { return this._glModelViewMatrix(t, e) } async _detectAndMatch(t, e) { const { featurePoints: s } = this.cropDetector.detectMoving(t), { targetIndex: o, modelViewTransform: r } = await this._workerMatch(s, e); return { targetIndex: o, modelViewTransform: r } } async _trackAndUpdate(t, e, s) { const { worldCoords: o, screenCoords: r } = this.tracker.track(t, e, s); return o.length < 4 ? null : await this._workerTrackUpdate(e, { worldCoords: o, screenCoords: r }) } processVideo(t) { if (this.processingVideo) return; this.processingVideo = !0, this.trackingStates = []; for (let s = 0; s < this.markerDimensions.length; s++)this.trackingStates.push({ showing: !1, isTracking: !1, currentModelViewTransform: null, trackCount: 0, trackMiss: 0, filter: new K9({ minCutOff: this.filterMinCF, beta: this.filterBeta }) }); (async () => { for (; this.processingVideo;) { const s = this.inputLoader.loadInput(t); if (this.trackingStates.reduce((r, i) => r + (i.isTracking ? 1 : 0), 0) < this.maxTrack) { const r = []; for (let c = 0; c < this.trackingStates.length; c++)this.trackingStates[c].isTracking !== !0 && (this.interestedTargetIndex !== -1 && this.interestedTargetIndex !== c || r.push(c)); const { targetIndex: i, modelViewTransform: a } = await this._detectAndMatch(s, r); i !== -1 && (this.trackingStates[i].isTracking = !0, this.trackingStates[i].currentModelViewTransform = a) } for (let r = 0; r < this.trackingStates.length; r++) { const i = this.trackingStates[r]; if (i.isTracking) { let a = await this._trackAndUpdate(s, i.currentModelViewTransform, r); a === null ? i.isTracking = !1 : i.currentModelViewTransform = a } if (i.showing || i.isTracking && (i.trackMiss = 0, i.trackCount += 1, i.trackCount > this.warmupTolerance && (i.showing = !0, i.trackingMatrix = null, i.filter.reset())), i.showing && (i.isTracking ? i.trackMiss = 0 : (i.trackCount = 0, i.trackMiss += 1, i.trackMiss > this.missTolerance && (i.showing = !1, i.trackingMatrix = null, this.onUpdate && this.onUpdate({ type: "updateMatrix", targetIndex: r, worldMatrix: null })))), i.showing) { const a = this._glModelViewMatrix(i.currentModelViewTransform, r); i.trackingMatrix = i.filter.filter(Date.now(), a); let c = []; for (let u = 0; u < i.trackingMatrix.length; u++)c[u] = i.trackingMatrix[u]; t.width === this.inputHeight && t.height === this.inputWidth && (c = this.getRotatedZ90Matrix(c)), this.onUpdate && this.onUpdate({ type: "updateMatrix", targetIndex: r, worldMatrix: c }) } } s.dispose(), this.onUpdate && this.onUpdate({ type: "processDone" }), await jp.nextFrame() } })() } stopProcessVideo() { this.processingVideo = !1 } async detect(t) { const e = this.inputLoader.loadInput(t), { featurePoints: s, debugExtra: o } = await this.cropDetector.detect(e); return e.dispose(), { featurePoints: s, debugExtra: o } } async match(t, e) { const { modelViewTransform: s, debugExtra: o } = await this._workerMatch(t, [e]); return { modelViewTransform: s, debugExtra: o } } async track(t, e, s) { const o = this.inputLoader.loadInput(t), r = this.tracker.track(o, e, s); return o.dispose(), r } async trackUpdate(t, e) { return e.worldCoords.length < 4 ? null : await this._workerTrackUpdate(t, e) } _workerMatch(t, e) { return new Promise(async (s, o) => { this.workerMatchDone = r => { s({ targetIndex: r.targetIndex, modelViewTransform: r.modelViewTransform, debugExtra: r.debugExtra }) }, this.worker.postMessage({ type: "match", featurePoints: t, targetIndexes: e }) }) } _workerTrackUpdate(t, e) { return new Promise(async (s, o) => { this.workerTrackDone = a => { s(a.modelViewTransform) }; const { worldCoords: r, screenCoords: i } = e; this.worker.postMessage({ type: "trackUpdate", modelViewTransform: t, worldCoords: r, screenCoords: i }) }) } _glModelViewMatrix(t, e) { const s = this.markerDimensions[e][1]; return [t[0][0], -t[1][0], -t[2][0], 0, -t[0][1], t[1][1], t[2][1], 0, -t[0][2], t[1][2], t[2][2], 0, t[0][1] * s + t[0][3], -(t[1][1] * s + t[1][3]), -(t[2][1] * s + t[2][3]), 1] } _glProjectionMatrix({ projectionTransform: t, width: e, height: s, near: o, far: r }) { const i = [[2 * t[0][0] / e, 0, -(2 * t[0][2] / e - 1), 0], [0, 2 * t[1][1] / s, -(2 * t[1][2] / s - 1), 0], [0, 0, -(r + o) / (r - o), -2 * r * o / (r - o)], [0, 0, -1, 0]], a = []; for (let c = 0; c < 4; c++)for (let l = 0; l < 4; l++)a.push(i[l][c]); return a } } const U9 = `<div class="mindar-ui-overlay mindar-ui-loading">
  <div class="loader"/>
</div>
`, Y9 = `<div class="mindar-ui-overlay mindar-ui-compatibility">
  <div class="content">
    <h1>Failed to launch :(</h1>
    <p>
      Looks like your device/browser is not compatible.
    </p>

    <br/>
    <br/>
    <p>
      Please try the following recommended browsers:
    </p>
    <p>
      For Android device - Chrome
    </p>
    <p>
      For iOS device - Safari
    </p>
  </div>
</div>
`, Q9 = `<div class="mindar-ui-overlay mindar-ui-scanning">
  <div class="scanning">
    <div class="inner">
      <div class="scanline"/>
    </div>
  </div>
</div>
`, J9 = ".mindar-ui-overlay{display:flex;align-items:center;justify-content:center;position:absolute;left:0;right:0;top:0;bottom:0;background:transparent;z-index:2}.mindar-ui-overlay.hidden{display:none}.mindar-ui-loading .loader{border:16px solid #222;border-top:16px solid white;opacity:.8;border-radius:50%;width:120px;height:120px;animation:spin 2s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.mindar-ui-compatibility .content{background:black;color:#fff;opacity:.8;text-align:center;margin:20px;padding:20px;min-height:50vh}@media (min-aspect-ratio: 1/1){.mindar-ui-scanning .scanning{width:50vh;height:50vh}}@media (max-aspect-ratio: 1/1){.mindar-ui-scanning .scanning{width:80vw;height:80vw}}.mindar-ui-scanning .scanning .inner{position:relative;width:100%;height:100%;opacity:.8;background:linear-gradient(to right,white 10px,transparent 10px) 0 0,linear-gradient(to right,white 10px,transparent 10px) 0 100%,linear-gradient(to left,white 10px,transparent 10px) 100% 0,linear-gradient(to left,white 10px,transparent 10px) 100% 100%,linear-gradient(to bottom,white 10px,transparent 10px) 0 0,linear-gradient(to bottom,white 10px,transparent 10px) 100% 0,linear-gradient(to top,white 10px,transparent 10px) 0 100%,linear-gradient(to top,white 10px,transparent 10px) 100% 100%;background-repeat:no-repeat;background-size:40px 40px}.mindar-ui-scanning .scanning .inner .scanline{position:absolute;width:100%;height:10px;background:white;animation:move 2s linear infinite}@keyframes move{0%,to{top:0%}50%{top:calc(100% - 10px)}}"; class EI { constructor({ uiLoading: t, uiScanning: e, uiError: s }) { const o = document.createElement("style"); o.innerText = J9, document.head.appendChild(o), t === "yes" ? this.loadingModal = this._loadHTML(U9) : t !== "no" && (this.loadingModal = document.querySelector(t)), s === "yes" ? this.compatibilityModal = this._loadHTML(Y9) : s !== "no" && (this.compatibilityModal = document.querySelector(s)), e === "yes" ? this.scanningMask = this._loadHTML(Q9) : e !== "no" && (this.scanningMask = document.querySelector(e)), this.hideLoading(), this.hideCompatibility(), this.hideScanning() } showLoading() { this.loadingModal && this.loadingModal.classList.remove("hidden") } hideLoading() { this.loadingModal && this.loadingModal.classList.add("hidden") } showCompatibility() { this.compatibilityModal && this.compatibilityModal.classList.remove("hidden") } hideCompatibility() { this.compatibilityModal && this.compatibilityModal.classList.add("hidden") } showScanning() { this.scanningMask && this.scanningMask.classList.remove("hidden") } hideScanning() { this.scanningMask && this.scanningMask.classList.add("hidden") } _loadHTML(t) { const e = document.createElement("template"); e.innerHTML = t.trim(); const s = e.content.firstChild; return document.getElementsByTagName("body")[0].appendChild(s), s } } window.MINDAR || (window.MINDAR = {}), window.MINDAR.IMAGE = { Controller: LI, Compiler: RI, UI: EI }, AFRAME.registerSystem("mindar-image-system", { container: null, video: null, processingImage: !1, init: function () { this.anchorEntities = [] }, tick: function () { }, setup: function ({ imageTargetSrc: n, maxTrack: t, showStats: e, uiLoading: s, uiScanning: o, uiError: r, missTolerance: i, warmupTolerance: a, filterMinCF: c, filterBeta: l }) { this.imageTargetSrc = n, this.maxTrack = t, this.filterMinCF = c, this.filterBeta = l, this.missTolerance = i, this.warmupTolerance = a, this.showStats = e, this.ui = new EI({ uiLoading: s, uiScanning: o, uiError: r }) }, registerAnchor: function (n, t) { this.anchorEntities.push({ el: n, targetIndex: t }) }, start: function () { this.container = this.el.sceneEl.parentNode, this.showStats && (this.mainStats = new Stats, this.mainStats.showPanel(0), this.mainStats.domElement.style.cssText = "position:absolute;top:0px;left:0px;z-index:999", this.container.appendChild(this.mainStats.domElement)), this.ui.showLoading(), this._startVideo() }, switchTarget: function (n) { this.controller.interestedTargetIndex = n }, stop: function () { this.pause(), this.video.srcObject.getTracks().forEach(function (t) { t.stop() }), this.video.remove(), this.controller.dispose() }, pause: function (n = !1) { n || this.video.pause(), this.controller.stopProcessVideo() }, unpause: function () { this.video.play(), this.controller.processVideo(this.video) }, _startVideo: function () { if (this.video = document.createElement("video"), this.video.setAttribute("autoplay", ""), this.video.setAttribute("muted", ""), this.video.setAttribute("playsinline", ""), this.video.style.position = "absolute", this.video.style.top = "0px", this.video.style.left = "0px", this.video.style.zIndex = "-2", this.container.appendChild(this.video), !navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { this.el.emit("arError", { error: "VIDEO_FAIL" }), this.ui.showCompatibility(); return } navigator.mediaDevices.getUserMedia({ audio: !1, video: { facingMode: "environment" } }).then(n => { this.video.addEventListener("loadedmetadata", () => { this.video.setAttribute("width", this.video.videoWidth), this.video.setAttribute("height", this.video.videoHeight), this._startAR() }), this.video.srcObject = n }).catch(n => { console.log("getUserMedia error", n), this.el.emit("arError", { error: "VIDEO_FAIL" }) }) }, _startAR: async function () { const n = this.video; this.container, this.controller = new LI({ inputWidth: n.videoWidth, inputHeight: n.videoHeight, maxTrack: this.maxTrack, filterMinCF: this.filterMinCF, filterBeta: this.filterBeta, missTolerance: this.missTolerance, warmupTolerance: this.warmupTolerance, onUpdate: e => { if (e.type === "processDone") this.mainStats && this.mainStats.update(); else if (e.type === "updateMatrix") { const { targetIndex: s, worldMatrix: o } = e; for (let i = 0; i < this.anchorEntities.length; i++)this.anchorEntities[i].targetIndex === s && this.anchorEntities[i].el.updateWorldMatrix(o); this.anchorEntities.reduce((i, a) => i || a.el.el.object3D.visible, !1) ? this.ui.hideScanning() : this.ui.showScanning() } } }), this._resize(), window.addEventListener("resize", this._resize.bind(this)); const { dimensions: t } = await this.controller.addImageTargets(this.imageTargetSrc); for (let e = 0; e < this.anchorEntities.length; e++) { const { el: s, targetIndex: o } = this.anchorEntities[e]; o < t.length && s.setupMarker(t[o]) } await this.controller.dummyRun(this.video), this.el.emit("arReady"), this.ui.hideLoading(), this.ui.showScanning(), this.controller.processVideo(this.video) }, _resize: function () { const n = this.video, t = this.container; let e, s; const o = n.videoWidth / n.videoHeight, r = t.clientWidth / t.clientHeight; o > r ? (s = t.clientHeight, e = s * o) : (e = t.clientWidth, s = e / o); const i = this.controller.getProjectionMatrix(), a = 2 * Math.atan(1 / i[5] / s * t.clientHeight) * 180 / Math.PI, c = i[14] / (i[10] - 1), l = i[14] / (i[10] + 1); i[5] / i[0]; const u = t.clientWidth / t.clientHeight, h = t.getElementsByTagName("a-camera")[0].getObject3D("camera"); h.fov = a, h.aspect = u, h.near = c, h.far = l, h.updateProjectionMatrix(), this.video.style.top = -(s - t.clientHeight) / 2 + "px", this.video.style.left = -(e - t.clientWidth) / 2 + "px", this.video.style.width = e + "px", this.video.style.height = s + "px" } }), AFRAME.registerComponent("mindar-image", { dependencies: ["mindar-image-system"], schema: { imageTargetSrc: { type: "string" }, maxTrack: { type: "int", default: 1 }, filterMinCF: { type: "number", default: -1 }, filterBeta: { type: "number", default: -1 }, missTolerance: { type: "int", default: -1 }, warmupTolerance: { type: "int", default: -1 }, showStats: { type: "boolean", default: !1 }, autoStart: { type: "boolean", default: !0 }, uiLoading: { type: "string", default: "yes" }, uiScanning: { type: "string", default: "yes" }, uiError: { type: "string", default: "yes" } }, init: function () { const n = this.el.sceneEl.systems["mindar-image-system"]; n.setup({ imageTargetSrc: this.data.imageTargetSrc, maxTrack: this.data.maxTrack, filterMinCF: this.data.filterMinCF === -1 ? null : this.data.filterMinCF, filterBeta: this.data.filterBeta === -1 ? null : this.data.filterBeta, missTolerance: this.data.missTolerance === -1 ? null : this.data.missTolerance, warmupTolerance: this.data.warmupTolerance === -1 ? null : this.data.warmupTolerance, showStats: this.data.showStats, uiLoading: this.data.uiLoading, uiScanning: this.data.uiScanning, uiError: this.data.uiError }), this.data.autoStart && this.el.sceneEl.addEventListener("renderstart", () => { n.start() }) }, remove: function () { this.el.sceneEl.systems["mindar-image-system"].stop() } }), AFRAME.registerComponent("mindar-image-target", { dependencies: ["mindar-image-system"], schema: { targetIndex: { type: "number" } }, postMatrix: null, init: function () { this.el.sceneEl.systems["mindar-image-system"].registerAnchor(this, this.data.targetIndex), this.invisibleMatrix = new AFRAME.THREE.Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); const t = this.el.object3D; t.visible = !1, t.matrixAutoUpdate = !1, t.matrix = this.invisibleMatrix }, setupMarker([n, t]) { const e = new AFRAME.THREE.Vector3, s = new AFRAME.THREE.Quaternion, o = new AFRAME.THREE.Vector3; e.x = n / 2, e.y = n / 2 + (t - n) / 2, o.x = n, o.y = n, o.z = n, this.postMatrix = new AFRAME.THREE.Matrix4, this.postMatrix.compose(e, s, o) }, updateWorldMatrix(n) { if (this.el.emit("targetUpdate"), !this.el.object3D.visible && n !== null ? this.el.emit("targetFound") : this.el.object3D.visible && n === null && this.el.emit("targetLost"), this.el.object3D.visible = n !== null, n === null) { this.el.object3D.matrix = this.invisibleMatrix; return } var t = new AFRAME.THREE.Matrix4; t.elements = n, t.multiply(this.postMatrix), this.el.object3D.matrix = t } })
})();